VarunKrish

Connecting to MySQL from Java

I would like to highlight how to establish a connection between MySQL a database and your JAVA app.

I assume you have installed MySQL and Java .

You must download the Mysql Connector/J 3.1 from mysql.com .

I downloaded the file mysql-connector-java-3.1.13.tar.gz and used the file

mysql-connector-java-3.1.13-bin.jar

Now in the Java class where want to connect to the MySQL database , addthe following code
[code lang=”java”]

Class.forName(“com.mysql.jdbc.Driver”) ;

Connection Con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/

database_name”,”user”,”pass”);

[/code]

Now you can use the Con object to carry out the queries.

Exit mobile version