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.

Published by

Varun Krish

Varun Krish has been dabbling with computers and websites for almost 2 decades. He has traveled to over 30 countries and hopes to visit every country on earth one day. He is currently the Editor-in-Chief of FoneArena.com and also advises startups and product companies on how to build better products. You can follow him on @varunkrish

Leave a Reply

Your email address will not be published.