Trying to use MySQL cannot make a connection to the driver.
Please help.. I am totally at a stand-still trying to use MySQL JDBC
I keep getting the following error..
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
No matter what I do..
I have the classpath set in WinXP to
.;c:\mysql\mysql-connector-java-5.1.15-bin.jar
The file does exists and when I go to the cmd prompt and issue
the command
c:>echo %classpath%
It shows me: .;c:\mysql\mysql-connector-java-5.1.15-bin.jar
I also have my runtime configuration set to:
"$[JavaHome]\bin\java.exe -cp .;c:\mysql\mysql-connector-java-5.1.15-bin.jar"
I am using JCreator for development.. I'm new to Java and it is a little less confusing than Eclipse..
I have read every post on this forum that pertains to this error, but, I just can't get it resolved.
This is the code that I am using to test the run.. It compiles and runs fine.. The error is caught by the handler..
import java.sql.*;
public class Test
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "testuser";
String password = "testpass";
String url = "jdbc:mysql://localhost/testuser";
Class.forName ("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
System.out.println (e);
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
I also have a problem with the odbc connection.
I have a testdb access database setup in the odbc admin: using username=admin and password=""; still no connection to any kind of database. I have also set up sqlite and it seems to work in php, but,
I can't get a connection to ANY database in java.
import java.sql.*;
public class Test
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "admin";
String password = "";
String url = "jdbc:odbc:testdb";
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
System.out.println (e);
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
I was able to change the -cp flags in JCreator
I was able to change the classpath -cp in JCreator runtime and this worked for me.. It was deff how I was compiling..
Thanks for your help!