Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : J2EE : JDBC : Connecting to a MySQL Database using Connector/J JDBC Driver Signup · Login
Author Thread
Connecting to a MySQL Database using Connector/J JDBC Driver
Posted in tutorial: Connecting to a MySQL Database using Connector/J JDBC Driver
·  bruceaj
User
Joined: 25 Sep 2009
Total Posts: 2
Connecting to a MySQL Database using Connector/J JDBC Driver
Posted: 25 Sep 2009
I keep getting Exception:com.mysql.jbdc.Driver when I run the example code in the above tutorial. I am using
jdk1.6.0_16
mysql-connector-java-5.1.10-bin.jar
NetBeans IDE 6.7.1
I can connect to the MySQL database from the command line using the values specified in DriverManage.getConnection function. I can run the example both from NetBeans and from the command line. I get the same results in both cases. I have path to mysql.....-bin.jar, including the filename in my classpath.
·  bruceaj
User
Joined: 25 Sep 2009
Total Posts: 2
Fixed
Posted: 25 Sep 2009
I am one dummy! I had jdbc spelled jbdc. Took some time to find. Thanks... Now on to do some queries..

·  craigmadsen
User
Joined: 23 Oct 2009
Total Posts: 1
Re: Connecting to a MySQL Database using Connector/J JDBC Driver
Posted: 23 Oct 2009
I'm getting the following error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Here's my code:

import java.sql.Connection;
import java.sql.DriverManager;

public class MySQLConnection {
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "password";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
} // end class MySQLConnection

I get this error on the line: Class.forName(driver).newInstance();
I am running MySQL 5.1
Windows XP SP2
The folder that houses my JDBC driver (5.1) executable jar file, IS ON MY CLASSPATH!


Thanks,

Craig

Users Subscribed To This Thread
bruceaj   craigmadsen  

Users Who Have Visited This Thread In Last 24 Hours
16 Visitors

Login
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.