how to connect to mysql database ?

hi friends i am new to jdbc .I want to connect my program to mysql5.0 database.
I compiled the below program from the c:\ drive. But at run time i am getting classnot found Exception:com.mysql.jdbc.Driver and in the below program in the string dburl the hello is the database name which i created

Issue with com.mysql.jdbc.Driver classpath and Jar file.
MQSQL Driver class has to be in class path while executing your JDBC program.
Java databse connectivity jar contains interfaces like statement ,result set etc.
Each vendor will provide own implementation of JDBC . To execute oracle jdbc program you need to have jar file from oracle.
as i know above statment applies all of the databases.
here solutio is you have to include MQSQL Jar file in the classpath. Which IDE you are using ?
MYSQL Jar All the Best

teja dharma
Ranch Hand

Joined: Feb 07, 2009
Posts: 51

posted Jan 17, 2010 03:16:45

0

srinivas srinivasmeenavalli wrote:Issue with com.mysql.jdbc.Driver classpath and Jar file.
MQSQL Driver class has to be in class path while executing your JDBC program.
Java databse connectivity jar contains interfaces like statement ,result set etc.
Each vendor will provide own implementation of JDBC . To execute oracle jdbc program you need to have jar file from oracle.
as i know above statment applies all of the databases.
here solutio is you have to include MQSQL Jar file in the classpath. Which IDE you are using ?
MYSQL Jar All the Best

I compiled the program by setting the class path like this
javac jdbcdemo.java -classpath "C:\Documents and Settings\teja\MyDocuments\mysql-connector-java-5.1.10\mysql-connector-java-5.1.10.jar" I mean jarfile is present in C:\Documents and Settings\teja\MyDocuments\mysql-connector-java-5.1.10\mysql-connector-java-5.1.10.jar at compile time no error but at run time i am getting nullpoinerexception

No, you should provide the same set of jars used to compile when running too ("java -cp <setofJARs> classname").

teja dharma
Ranch Hand

Joined: Feb 07, 2009
Posts: 51

posted Jan 18, 2010 05:42:39

0

Vijitha Kumara wrote:

teja tej wrote:At runtime java jdbcdemo :

No, you should provide the same set of jars used to compile when running too ("java -cp <setofJARs> classname").

At runtime I gave the command java -cp "C:\Documents and Settings\teja\MyDocuments\mysql-connector-java-5.1.10\mysql-connector-java-5.1.10.jar" jdbcdemo
This time i got java.lang.NoClassDefFoundError:jdbcdemo

teja tej wrote:At runtime I gave the command java -cp "C:\Documents and Settings\teja\MyDocuments\mysql-connector-java-5.1.10\mysql-connector-java-5.1.10.jar" jdbcdemo
This time i got java.lang.NoClassDefFoundError:jdbcdemo

When you use classpath switch you have to point all the classes/jars which are required to run the application, because default/classpath entry in environment is ignored. So in this case you should append the path to the "jdbcdemo" (and any other classes required) to the "classpath" switch as well.