Friday 13 December 2013

How to connect to MySQL database using JDBC?

Connecting to MySQL database using JDBC

Open your server.xml file and append the following lines. Make sure the JDBC driver “org.gjt.mm.mysql.Driver” must be in classpath. You can download it from http://dev.mysql.com/downloads/connector/j/5.1.html

// loads the JDBC driver
   Class.forName("org.gjt.mm.mysql.Driver").newInstance();
   // get a database connection
   Connection conn = DriverManager.getConnection(
       "jdbc:mysql://hostname/databaseName",
       "user",
       "password");

No comments:

Post a Comment