Dear All,
I have a java application which link to db on another computer on the local lan. The problem I have install jdk_1.6_21 without any problem. Then I have paste mysql-connector-java-5.1.14-bin.jar in /usr/java/jdk1.6.0_21/jre/lib/ext. When I compile my program has no problem when I try to run I get this error java.sql.SQLException: No driver found. I have been doing this method all this while it works suddenly this new machine have this problem. Any help please.My Os is centos 5.5.

make sure you put a System.out.println() statement in all your catch clause which will p[rint the error encountered

Dear Pbl,
I have added extra codes like this and after that below is the error.

catch (SQLException ex)
{
System.out.println("MyError:Error : "+ex);
ex.printStackTrace();
}

MyError:Error : java.sql.SQLException: No driver found for jdbc:mysql://192.168.2.25:3306/db1?user=userDB1&password=*****
java.sql.SQLException: No driver found for jdbc:mysql://192.168.2.25:3306/db1?user=userDB1&password=*****
   at java.sql.DriverManager.getDriver(libgcj.so.7rh)
   at java.sql.DriverManager.getConnection(libgcj.so.7rh)
   at java.sql.DriverManager.getConnection(libgcj.so.7rh)
   at basicClient.main(basicClient.java:46)

How are you launching the application? Make sure that the driver JAR is listed in the classpath when you launch the application and you should be good to go.

java -cp app.jar:mysql.jar your.pkg.MainClass

Also, never ever mess with your default JDK installation. If your application requires a third-party JAR, supply the same using the -cp switch when compiling and running Java programs rather than "pasting" JARs to the JDK directory.

Dear Sos,
How I can call is like this java basicClient. The problem it have been working fine in all computer except for this one special case. Can it be some installation problem of the O.S? Thank you.

Like already mentioned, tell me how do you exactly launch the application right now. Use the template provided in my previous post to launch your application by setting the appropriate classpath.

Dear SOS,
Actually what is the difference between path and classpath I am quite confuse here too. Now I launch the application via command prompt. I hope I answer you. Thank you.

The PATH environment variable is typically used by OS to find executables so that you can simply do "javac SomeFile" instead of "/usr/bin/jdk/javac SomeFile". The classpath is a Java specific property which tells the VM where to find all the necessary class/JAR files. (There is also a CLASSPATH environment variable which again shouldn't be messed with; there are better ways around it like setting classpath when firing javac or java).

In your case, you simply need to "set the classpath" when "invoking the java command". E.g. java -classpath mysql.jar:yourapplicationjar pkg.Main

Dear SOS,
How define the path for the mysql jar or must I put in the same folder as my application is it? So in my case will it be -classpath mysql.jar:basicClient?

You can place the JAR file anywhere, just make sure you provide the full JAR path when specifying the classpath for the java command.

Dear All,
I have a java application which link to db on another computer on the local lan. The problem I have install jdk_1.6_21 without any problem. Then I have paste mysql-connector-java-5.1.14-bin.jar in /usr/java/jdk1.6.0_21/jre/lib/ext. When I compile my program has no problem when I try to run I get this error java.sql.SQLException: No driver found. I have been doing this method all this while it works suddenly this new machine have this problem. Any help please.My Os is centos 5.5.

Are you maybe ignoring the exception when you load the driver (or are you using the inherent "Service" capabilites as of Java 6/JDBC 4 (is the current version 4 or 5?))? Or have you mangled the connection url? As that error is not caused by a missing driver, but rather by the attempt to use a driver that has not been loaded (or a mangled connection url so that JDBC doesn't know what driver it should be using which amounts to the same thing).

Dear All,
At last I found out actually the problem was due to my linux was corrupted and having problem. So now all is back to normal thank you once again to all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.