Results 1 to 4 of 4
- 03-06-2011, 08:25 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 21
- Rep Power
- 0
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 */ }
}
}
}
}
- 03-06-2011, 10:29 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 21
- Rep Power
- 0
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 */ }
}
}
}
}
- 03-07-2011, 11:00 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Use e.printStackTrace() to get all the info for the error.
Next, how are you running this?
If from the command line then what is your full command.
Don't bother setting the classpath on your OS. Waste of time.
The correct way is the -cp flag, as you have later on.
List the contents of "c:\mysql\" and show them here.
As for your second post, what errors are you getting?
- 03-09-2011, 11:15 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 21
- Rep Power
- 0
Similar Threads
-
com.mysql.jdbc.Driver
By uthpalaw in forum EclipseReplies: 2Last Post: 10-14-2010, 05:09 AM -
ClassNotFoundException com.mysql.jdbc.Driver
By Heather in forum JDBCReplies: 4Last Post: 03-31-2010, 12:08 PM -
Problems with MySQL Driver
By islan in forum JDBCReplies: 7Last Post: 08-06-2009, 04:47 PM -
can't register a MySQL driver
By prfalco in forum New To JavaReplies: 4Last Post: 02-03-2008, 11:13 PM -
mysql driver problem
By mokingsu in forum JDBCReplies: 4Last Post: 01-17-2008, 05:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks