|
-
Feb 21st, 2006, 02:46 AM
#1
Thread Starter
Addicted Member
Java Mysql Driver Error
I have just installed Mysql 5 and MySQL Connector/J 5.0. I try to load driver. Here is my code.
VB Code:
import java.sql.*;
public class TestMysql
{
public static void main(String args[]) throws Exception{
String driver = "com.mysql.jdbc.Driver";
Class.forName( driver );
}
}
Then i compiled and run. The following message display.
VB Code:
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driv
er
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.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at TestMysql.main(TestMysql.java:7)
What does it mean? I am new to Java and Mysql. Please tell me step by step to connect Java with Mysql.
-
Feb 21st, 2006, 06:32 AM
#2
Frenzied Member
Re: Java Mysql Driver Error
That looks right... Have you even installed mysql??
-
Feb 21st, 2006, 02:55 PM
#3
Re: Java Mysql Driver Error
 Originally Posted by System_Error
That looks right... Have you even installed mysql??
It's not that he didn't install but I beleive the problem is in the IDE he's using
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Feb 21st, 2006, 08:35 PM
#4
Thread Starter
Addicted Member
Re: Java Mysql Driver Error
I have installed MySql already. I didn't use any Java IDE. I use Notepad and compile and run it in DOS Prompt.
-
Feb 21st, 2006, 08:40 PM
#5
Frenzied Member
Re: Java Mysql Driver Error
Try explicitly tellling the JVM which to use:
java -Djdbc.drivers=com.mysql.jdbc.Driver YourJavaProgram
or something like that.
You could also do this:
Class.forName("com.mysql.jdbc.Driver").newInstance();
PS: Good job on writing and compiling the real way
-
Feb 21st, 2006, 08:40 PM
#6
Fanatic Member
Re: Java Mysql Driver Error
Code:
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=procopio&password=alibi");
} catch (Exception ex) {
ex.printStackTrace();
}
Works fine with me. You should check the classpath variable for the runtime to locate the class com.mysql.jdbc.Driver.
Please see, http://vbforums.com/showthread.php?t...ight=classpath
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|