i've been trying to connect java with mysql db using the jdbc connector version 5.0.5...
i am also using mysql version 5...
i create a folder structure C:\Java\Classes.zip
i have added the mysql-connector-java-5.0.4-bin.jar file to the Classes.zip file, also set the CLASSPATH to C:\Java\Classes.zip
After i compile the java program the above mentioned error still comes up!!
the connection part of the program:
--------------------------------------...
try {
Class.forName("com.mysql.jdbc.Driver").n...
String url = "jdbc:mysql://localhost:3306/db";
String user = "root";
String pass = "";
con = DriverManager.getConnection(url,user,pas...
System.out.println("Connected");
}
con.close();
}
catch (Exception f) {
System.out.println("Error: " + f);
}
Error: java.lang.ClassNotFoundExcepti... com.mysql.jdbc.Driver?
There is no error in your code, but certainly, if you are trying to make connections from an stand alone application, you must copy the mysql-connector jar file into this two directories:
%26lt; your jdk dir %26gt;\jre\lib\
%26lt; your jdk dir %26gt;\jre\lib\ext\
If you are using netbeans like your default IDE, restart it after copying this files.
Hope this helps.
Reply:your answer helped me solve the issue. did not had to copy the file to both locations. had to copy it to this location only: jdk dir %26gt;\jre\lib\ext\
thanks Report It
Reply:You can't just add that file to your classes.zip.
I am not sure what exactly that file is, because the name is truncated in your message. If it has .jar in the end, you need to add it to the classpath - just append a ';' and the path to the file to the CLASSPATH after Classes.zip
if it is not .jar, you may need to do some additional steps - it could be an archive, containing .jar inside, or it could be an installer program that you need to run etc...
Reply:the classpath variable is not set.
code looks good.
just set it and it should run !!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment