Results 1 to 4 of 4
Thread: connecting to a mysql db
- 10-27-2011, 07:29 PM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 235
- Rep Power
- 3
connecting to a mysql db
I am trying to connect to a databse. here is my code so far:
i am getting this error:Java Code:import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Connect2 { public static void main(String args[]) { String dbtime; String dbUrl = "jdbc:mysql:/dbnumber.db.1and1.com/uploader"; String dbClass = "com.mysql.jdbc.Driver"; String query = "Select * FROM members"; try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection(dbUrl); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { dbtime = rs.getString(1); System.out.println(dbtime); } // end while con.close(); } // end try catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } // end main } // end class
I am familiar with connecting to mysql via php, but not java.Java Code:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at Connect2.main(Connect2.java:17)
thanks in advance.
- 10-27-2011, 09:12 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: connecting to a mysql db
That driver is most likely stored in a .jar file somewhere; add that .jar file to your classpath.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-28-2011, 03:00 AM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
Re: connecting to a mysql db
Check out my tutorial in youtube: "Lesson 8. Connecting Java to MySql ODBC easiest way"
- 10-30-2011, 12:43 AM #4
Senior Member
- Join Date
- Feb 2011
- Posts
- 235
- Rep Power
- 3
Similar Threads
-
Connecting Mysql with J2ME
By razmyasdfg in forum CLDC and MIDPReplies: 2Last Post: 05-22-2011, 10:40 PM -
connecting mysql with netbeans
By angelia in forum New To JavaReplies: 3Last Post: 05-15-2011, 11:30 AM -
Error while connecting to mysql server
By Anandt88 in forum JDBCReplies: 1Last Post: 08-16-2010, 02:37 PM -
Connecting a MySQL DB through Eclipse
By mitty in forum New To JavaReplies: 3Last Post: 02-01-2010, 09:22 AM -
connecting to mysql database
By javagal in forum NetBeansReplies: 2Last Post: 08-04-2007, 12:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks