Results 1 to 8 of 8
- 05-06-2010, 03:52 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 14
- Rep Power
- 0
ClassNotFoundException when trying to connect to Mysql database
Hi all,
I am trying to get my program to connect to a mysql database, and I am getting a ClassNotFoundException: com.mysql.jdbc.Driver error. My code is below:
Thanks in advance for your helpJava Code:public void connect() { Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection("jdbc:mysql://localhost/cmp_wrkr", "root", "myPassHere"); //TODO remove debug System.out.println("Connected"); } catch(Exception e) { e.printStackTrace(); } finally { try { if(conn != null) conn.close(); } catch(SQLException e) {} }
- 05-06-2010, 07:16 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Add the mysql driver to the classpath.
- 05-08-2010, 09:46 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 14
- Rep Power
- 0
Do you have an example of this? I can't seem to find a good one.
-
Much depends on how you are compiling and running the code. Are you doing this on the command line? In NetBeans? Eclipse? JCreator? Other?
If the command line, have you looked at the standard Sun tutorials on the classpath?
- 05-08-2010, 10:54 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 14
- Rep Power
- 0
I am trying to do this using Eclipse
-
- 05-09-2010, 12:24 AM #7
Member
- Join Date
- Apr 2010
- Posts
- 14
- Rep Power
- 0
Awesome, it worked. Thanks so much Fubar!
-
Similar Threads
-
Unable to connect to remote mysql database using IP Address
By kranthipoturaju in forum JDBCReplies: 4Last Post: 04-28-2010, 06:13 PM -
ClassNotFoundException com.mysql.jdbc.Driver
By Heather in forum JDBCReplies: 4Last Post: 03-31-2010, 12:08 PM -
Can NOT connect to Mysql
By zed420 in forum New To JavaReplies: 3Last Post: 12-18-2009, 08:26 PM -
How do you connect to a MYSQL database from Eclipse?
By Menre in forum Advanced JavaReplies: 15Last Post: 04-15-2009, 01:51 AM -
How to connect a Java program with MySQL database?
By Ms.Ranjan in forum JDBCReplies: 2Last Post: 06-12-2008, 07:09 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks