Showing posts with label JDBC driver. Show all posts
Showing posts with label JDBC driver. Show all posts

Thursday 20 February 2014

java mysql connection example easily

Connect to MySQL with JDBC driver



Here’s an example to show you how to connect to MySQL database via a JDBC driver. First, get a MySQL JDBC driver from here -MySQL JDBC Driver Download Here.

MySQL JDBC Driver  should be in same folder where you save your project.

1. Java JDBC connection example

Code snippets to use a JDBC driver to connect a MySQL database.
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql://hostname:port/dbname","username", "password");
conn.close();

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

Java & MySQL - Basic connection and insert values (NetBeans)