java jdbc connection to mysql problem

Posted by fatnjazzy on Stack Overflow See other posts from Stack Overflow or by fatnjazzy
Published on 2010-05-09T19:46:17Z Indexed on 2010/05/09 20:38 UTC
Read the original article Hit count: 228

Filed under:
|
|
|
|

Hi, I am trying to connect to mysql from java web application in eclipse.

 Connection con = null; 

  try {
    //DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection("jdbc:mysql://localhost/db_name","root" ,"");

    if(!con.isClosed())
      System.out.println("Successfully connected to " +
        "MySQL server using TCP/IP...");

  } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
  } finally {
    try {
      if(con != null)
        con.close();
    } catch(SQLException e) {
     System.out.println(e.toString());
    }
  }

I am always getting the Exception: com.mysql.jdbc.Driver

I have downloaded this jar http://forums.mysql.com/read.php?39,218287,220327

import it to the "java build path/lib"

the mysql version is 5.1.3 under.

running:

mysql 5.1.3 (db is up and running queries form PHP)

windows XP

java jee

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about jdbc