java cannot find mysql connector
I'm trying to use MySQL's JDBC connector for java but even though I set the CLASSPATH variable, java cannot find the com.mysql.jdbc.Driver class.
Code:
[jordan@Jordan-Laptop java-stuff]$ ls /usr/share/java |
EDIT (sorry)... I did not see where you echo-ed the CLASSPATH. It should be set to (something like):
Code:
CLASSPATH=./:/usr/share/java/mysql-connector-java.jar |
Quote:
Quote:
Code:
import java.sql.*; Code:
CLASSPATH=./:/usr/share/java/mysql-connector-java.jar Thanks |
Quote:
I just installed the relevant MySql packages on my other machine, setup the class-path, and then executed a program similar to yours. The application ran successfully. |
Maybe you need MySQL connector for Java
Take a look at http://www.mysql.com/downloads/connector/j/
|
Quote:
Code:
[jordan@Jordan-Laptop java-stuff]$ export CLASSPATH=./:/usr/share/java/mysql-connector-java.jar Quote:
|
The only other thing I can think of is that there is a firewall blocking the port on at least one of your machines.
Can you get the application to connect to MySQL if you run it on the localhost where mysqld is running? |
Quote:
Quote:
|
Quote:
Quote:
Code:
java -version |
Code:
$java -version |
As I stated earlier, I used a similar app to yours to test. I got it working on both under Ubuntu systems (10.04 and 10.11). Here's the code:
Code:
import java.sql.*; P.S. Check the file permissions for /usr/share/java/mysql-connector-java.jar to ensure that you can read it. |
Code:
[jordan@Jordan-Laptop java-stuff]$ ls -FGg /usr/share/java/mysql-connector-java.jar |
Jordanwb - Please execute and cut/paste the exact output of these three commands:
Code:
export CLASSPATH=./:/usr/share/java/mysql-connector-java.jar; echo $CLASSPATH |
Sure:
Code:
[jordan@Jordan-Laptop ~]$ cd ~/Desktop/java-stuff/ |
Cool - thanx.
Code:
ls -l /usr/share/java/mysql-connector-java.jar "mysql-connector-java.jar" is a symbolic link (NOT the .jar file itself). Q: Do you know if the file it's pointing to, "mysql-connector-java-5.1.15.jar" exists? Please run these commands (cut/paste both the command and the output, as you did before): Code:
ls -l /usr/share/java/mysql-connector-java.jar PS: There's no reason you couldn't just (re) download the MySql JDBC connector, and put it wherever you want. Just make sure your $CLASSPATH variable (or, better, "-cp" command-line option) points to it. |
All times are GMT -5. The time now is 08:52 AM. |