What is the MySQL JDBC driver connection string?

ravi kumar picture ravi kumar · Sep 22, 2009 · Viewed 379.1k times · Source

I am new to JDBC and I am trying to make a connection to a MySQL database. I am using Connector/J driver, but I cant find the JDBC connection string for my Class.forName() method.

Answer

Langali picture Langali · Sep 22, 2009

Assuming your driver is in path,

String url = "jdbc:mysql://localhost/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection (url, "username", "password");