Connect Java with MySql


1.Java installed.

2.WAMP(Windows Apache MySql PHP) installed.

Few Steps to Connect your Java Program with your MySql Backend.

Step 1:

Check that your Computer has Java Installed.

Step 2:

Download the MySql Connection for Java.

Step 3:

Put the downloaded JAR(Java Archive File) in to the location where JavaHome/jdkversion/jre/lib/ext ..

Inside to the ext Directory.

Step 4:

Write Java Code to Connect to the MySql Database.

Sample code to connect Java with MySql.

import java.sql.*;
class jdbc
public static void main(String ar[])
Class.forName (“com.mysql.jdbc.Driver”);
Connection con=DriverManager.getConnection(“jdbc:mysql://”,”root”,””);
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(“select * from tablenamehere”);
catch(Exception e)
System.out.println(“Error occurerd”);

Step 5:

Compile your Java using javac

On the Successful Completion of Java File you will see that the Class file has been created.

Run your Java File using java filename.

You will get Data from the MySql Database.

Feel free to share your comments and your Queries.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s