Results 1 to 4 of 4
  1. #1
    fortwnty420 is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default 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 */ }
    }
    }
    }
    }

  2. #2
    fortwnty420 is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default 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 */ }
    }
    }
    }
    }

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    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?

  4. #4
    fortwnty420 is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default 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!

Similar Threads

  1. com.mysql.jdbc.Driver
    By uthpalaw in forum Eclipse
    Replies: 2
    Last Post: 10-14-2010, 05:09 AM
  2. Replies: 4
    Last Post: 03-31-2010, 12:08 PM
  3. Problems with MySQL Driver
    By islan in forum JDBC
    Replies: 7
    Last Post: 08-06-2009, 04:47 PM
  4. can't register a MySQL driver
    By prfalco in forum New To Java
    Replies: 4
    Last Post: 02-03-2008, 11:13 PM
  5. mysql driver problem
    By mokingsu in forum JDBC
    Replies: 4
    Last Post: 01-17-2008, 05:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •