Java Code For Mysql Database Connection

Java code to connect database

Step 1:
          Download   mysql-connector-java-5.1.6-bin.jar and add in your project.

step 2:

Write this code to connect mysql

import java.sql.DriverManager;
import com.mysql.jdbc.Connection;

    Connection con = null;
        try {
            String JDBC_DRIVER = “com.mysql.jdbc.Driver”; 
            String DB_URL = “jdbc:mysql://localhost:3306/DB_NAME”;
            String USER = “root”;
             String PASS = “root”;
          con =(Connection) DriverManager.getConnection(DB_URL,USER,PASS);
           return  con;
        } catch (Exception e) {

Leave a Reply

Your email address will not be published. Required fields are marked *

36 − 28 =