Results 1 to 14 of 14
- 10-17-2009, 12:25 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
MySQL connectivity (hours wasted)
I have been searching through google for hours and tried everything I've found and still can't seem to get rid of this SQLException (No suitable driver found for mysql.//dbaddress/schema.......)
Here is a snippet of my code, if anyone could help that would be great, I'm at a loss.
Java Code:public Connection getConnection(String url) throws SQLException, IOException, ClassNotFoundException { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println("Class Not Found"); System.exit(1); } return DriverManager.getConnection(url, "BerlGeof",""); }
- 10-17-2009, 12:43 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
Well, maybe we could, if you showed us the url you used.
- 10-17-2009, 03:52 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
Sorry, I didn't think the url mattered since the error was that the class wasn't found. I figured it was something with the classpath and/or a jar file not being found.
jdbc:mysql://111.11.11.1/Schema_Name
Here is the full error too:
Java Code:java.sql.SQLException: No suitable driver found for jdbc:mysql://111.11.11.1/Sch ema_Nameuser=BerlGeof&password= at java.sql.DriverManager.getConnection(DriverManager.java:602) at java.sql.DriverManager.getConnection(DriverManager.java:207) at DB_Connection.getConnection(DB_Connection.java:74) at DB_Connection.<init>(DB_Connection.java:29) at EmployeeDash1.performComputation(EmployeeDash1.java:197) at EmployeeDash1.actionPerformed(EmployeeDash1.java:167) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19 95) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav a:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel .java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242 ) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL istener.java:236) at java.awt.Component.processMouseEvent(Component.java:6134) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5899) at java.awt.Container.processEvent(Container.java:2023) at java.awt.Component.dispatchEventImpl(Component.java:4501) at java.awt.Container.dispatchEventImpl(Container.java:2081) at java.awt.Component.dispatchEvent(Component.java:4331) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301 ) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895) at java.awt.Container.dispatchEventImpl(Container.java:2067) at java.awt.Window.dispatchEventImpl(Window.java:2458) at java.awt.Component.dispatchEvent(Component.java:4331) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre ad.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread. java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre ad.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
- 10-17-2009, 10:49 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
No. The error was not ClassNotFound, it was "no suitable driver found". That usually means that you either typed the url wrong, or that you loaded one driver but tried to use another.
Show the code with the url, as this
Java Code:No suitable driver found for jdbc:mysql://111.11.11.1/Sch ema_Nameuser=BerlGeof&password=
- 10-17-2009, 04:18 PM #5
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
Bear with me, my code is not complete as my main concern is getting the driver to connect.
Here is the method that is creating the connection object.
Sorry for the break in the name, I copied the error from the CMD line which put the line breaks in there itself. I left my schema name in there this time and just removed the IP. The port hasn't always been in there, I added it last night in an attempt to fix this issue but no luck. Lastly, as you can see in my getConnection method that I'm not creating the full URL with username and pass, I'm using the three arg method. The method is compiling that, should there be a ? between username and the schema name? I can try sending the URL as one whole string including the username and pass with the ?.
Java Code:public void performComputation() { try { String strResults = null; DB_Connection mysqlDB = new DB_Connection("jdbc:mysql://111.11.11.1:3306/dashboard_data"); //DataBase db = new DataBase(); //Get employee name, tokenize it into format that matches the report StringTokenizer st = new StringTokenizer((String)jcbEmployee.getSelectedItem()); firstName = st.nextToken(); lastName = st.nextToken(); String employee = lastName + ", " + firstName; System.out.println("Gathering data that matches employee " + employee); sqlQuery1 = "Select Employee, OperationCode, TransactionQuantity From Resources " + "where Employee = '" + employee + "'"; mysqlDB.showTablesInfo("person2"); //db.showTablesInfo(tableName); System.out.println("\n---- Query 1 ----"); //strResults = db.createQuery(sqlQuery1, 3); //jtResults.insert(strResults, 0); //db.close(); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } catch (IOException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
- 10-17-2009, 04:32 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
The url is okay and the Class name is okay, so, is the mysql jarfile on the classpath when the program starts, or are you creating a classloader and adding the jarfile later?
- 10-17-2009, 04:48 PM #7
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
OK, I'm going to go insane. I am using a different computer than last night and it's working. I will have to try again on Monday when I have access to the other computer again. I will post what my classpath contents are when I get back to the other Computer.
- 10-17-2009, 04:57 PM #8
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
All I can say is, take a close look at the url used on that "other computer".
- 10-19-2009, 02:53 PM #9
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
Interesting, it appears it was because I had the 5.0.8 jar file driver. The classpath was correct on the original PC but noticed it was 5.0.8 connector. I downloaded 5.1.0 and changed the classpath and now it works fine. I wouldn't think an old version would cause this issue I wasn't using any fancy SQL statements, just a SELECT * with no criteria.
- 10-19-2009, 04:00 PM #10
Member
- Join Date
- Aug 2009
- Posts
- 4
- Rep Power
- 0
Plz help me i hav a problem with this code...
error is class not found exception ... com.microsoft.sqlserver.jdbc.SQLServerDriver
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
}
catch(Exception ex)
{
ex.printStackTrace();
}Last edited by sparlay_pk; 10-20-2009 at 06:43 AM.
- 10-19-2009, 04:14 PM #11Java Code:
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
And why do you hijack a completely unrelated thread instead of starting a new one?Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 10-20-2009, 06:45 AM #12
Member
- Join Date
- Aug 2009
- Posts
- 4
- Rep Power
- 0
Plz help me i hav a problem with this code...
error is class not found exception ... com.microsoft.sqlserver.jdbc.SQLServerDriver.
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
}
catch(Exception ex)
{
ex.printStackTrace();
}
The space you see in (SQLServ erDriver) is not the part of origional file, it's due to the editor.
I have installed MS SQL 2005 ....Last edited by sparlay_pk; 10-20-2009 at 06:48 AM.
- 10-20-2009, 08:25 AM #13
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
So start your own thread!
- 10-21-2009, 08:18 AM #14
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
Similar Threads
-
im very new to java need help with taking years and turning it into days, hours, etc.
By mrnoahf in forum New To JavaReplies: 3Last Post: 08-11-2009, 01:18 AM -
MySQL/JDBC Mysql query output
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 02-13-2009, 02:57 AM -
sql connectivity
By prashant in forum JDBCReplies: 2Last Post: 12-27-2008, 05:05 AM -
Simple Project 4 or 5 Hours – Pay $100
By billaaa777 in forum Jobs OfferedReplies: 0Last Post: 08-30-2008, 01:45 AM -
ensure connectivity
By perdoname in forum JDBCReplies: 1Last Post: 04-22-2008, 03:29 AM
Bookmarks