How To Connect to MySQL with a JDBC Driver

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr
MySQL JDBC Java
MySQL JDBC Java

This example will show you how to connect to MySQL database via a JDBC driver.

First, download the MySQL JDBC Driver.

This will show you how to open a database connection.

To run this code, your need mysql-connector-java-{version}-bin.jar in your classpath.

JDBCMySQLExample.java

To run the code, put JDBCExample.java in the same folder as the MySQL JDBC driver (for example c:\test) and execute:

C:\test>java -cp c:\test\mysql-connector-java-5.1.8-bin.jar;c:\test JDBCExample

You should see:

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr