I am new to Linux and Java but have a few years MySQL experience; my ambition is migrate from Windows and Delphi to Linux and Java.
However, I seem unable to get Connector/J working with Java and Linux. (I have got it to work with Windows and Delphi).
I have saved mysql-connector-java-5.1.7-bin-jar in a directory and added a "export set ..." statement to etc/profile to set CLASSPATH.
My java program checks the existence of the -bin-jar file with the following code:
I also check that the CLASSPATH environment variable has been set up with
and this correctly displays the environment variable that I set up.
Now the bit that doesn't work:
I always get the "Unable to connect..." message. No doubt I'm doing something really silly. I've learnt quite a bit to get this far but can anyone push me in the right direction, please?
I am using NetBeans 6.0.1, Java 1.6.0_0, Ubuntu 8.04 in case that is relevant.
Andrew
Hampshire, UK
However, I seem unable to get Connector/J working with Java and Linux. (I have got it to work with Windows and Delphi).
I have saved mysql-connector-java-5.1.7-bin-jar in a directory and added a "export set ..." statement to etc/profile to set CLASSPATH.
My java program checks the existence of the -bin-jar file with the following code:
Code:
boolean exists = (new File(jarname)).exists();
if (exists)
System.out.println("jar found");
else
System.out.println("No jar file found");
Code:
String classp = System.getenv("CLASSPATH");
if (classp.equals(jarname))
System.out.println("Jar names match");
else
System.out.println("Jar names do NOT match");
System.out.println("CLASSPATH="+classp);
Now the bit that doesn't work:
Code:
private static final String dbClassName = "com.mysql.jdbc.Driver";
...
try
{
Class.forName(dbClassName);
System.out.println("Class.forName worked");
...
}
catch (Exception e)
{
System.out.println("Unable to connect to database server");
}
I am using NetBeans 6.0.1, Java 1.6.0_0, Ubuntu 8.04 in case that is relevant.
Andrew
Hampshire, UK