Home > Archive > Java Help > April 2007 > classpath problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I compile the follwing java code snippet to connect it to my MySQL
database using API downloaded from the MySQL's site:
import java.sql.*;
class First {
public static void main(String args[]) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/rdb?
user=aavi&password=abcdef");
} catch (Exception e) {
System.out.println(e);
}
}
}
I complie the code with command 'javac First.class -classpath <full
path to the mysql-connector-java-3.1.14-bin.jar file>'
The problem is that I end up with the
error:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
when I try to execute the class file.
Please help.
| |
| Lothar Kimmeringer 2007-04-27, 7:07 pm |
| Ravi wrote:
> I complie the code with command 'javac First.class -classpath <full
> path to the mysql-connector-java-3.1.14-bin.jar file>'
>
> The problem is that I end up with the
> error:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
>
> when I try to execute the class file.
You have to specify the same classpath when executing the
code, as well.
Regards, Lothar
--
Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
| |
| printdude1968@gmail.com 2007-04-27, 7:07 pm |
| On Apr 27, 5:24 pm, Lothar Kimmeringer <news200...@kimmeringer.de>
wrote:
> Ravi wrote:
>
>
>
> You have to specify the same classpath when executing the
> code, as well.
>
> Regards, Lothar
> --
> Lothar Kimmeringer E-Mail: spamf...@kimmeringer.de
> PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
>
> Always remember: The answer is forty-two, there can only be wrong
> questions!
Will it also work if he puts his Java Connector jar file in his lib/
ext directory like:
C:\Program Files\Java\jre1.6.0\lib\ext
| |
|
| Lothar Kimmeringer wrote:[color=darkred]
> Ravi wrote:
>
That's extremely unusual. I would have expected the command to be
javac -classpath <full path to the JAR> First.java
$ javac -help
Usage: javac <options> <source files>
--
Lew
|
|
|
|
|