#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    37
    Rep Power
    14

    Exclamation java / mysql connection


    hi

    i have a problem connecting to mySQL. My ConnectionPool works fine when I run my web-app on my machine, but when I upload the webapp, it doesn't want to connect to my hosted mysql database : it gives me the following error :

    Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.security.AccessControlException)

    port 3306 is the default port for mysql if you don't specify one...right?

    my host told me the database is located at localhost. i am using the mm.mysql driver to connect to it. it is in the WEB-INF\lib directory of my webapp. here is the code i use to get a connection :

    Connection conn = null;

    try{
    Class.forName("org.gjt.mm.mysql.Driver");
    String dbURL = "jdbc:mysql://localhost/database_name";
    String username = "username";
    String password = "password";
    conn = DriverManager.getConnection(dbURL, username, password);
    }
    catch(ClassNotFoundException cnfe){
    out.print("ClassNotFoundException : " + cnfe.getMessage());
    }
    catch(SQLException sqle){
    out.print("SQLException : " + sqle.getMessage());
    }

    -----------------------------------------------------------------------

    any ideas? i would really appreciate any help.

    thanx
    johann
  2. #2
  3. Prom night: 1973
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Dec 2001
    Posts
    1,152
    Rep Power
    28
    Could you change your catch block to:
    Code:
    catch(SQLException sqle){
       out.print("SQLException : " + sqle.getMessage());
       sqle.printStackTrace();
    }
    and then post the output of the stack trace? This could give a little more detail on where things are going wrong.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    37
    Rep Power
    14
    if anyone is interested, i sorted it out. I had two different versions of the mm.mysql driver. one installed on the server and the other in my WEB-INF/lib directory. i deleted the latter and now it works

IMN logo majestic logo threadwatch logo seochat tools logo