Copy the below given code to a file and save it as Connect.java
package com.test1.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author HOME
*/
public class Connect {
public static Connection connectDb(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/DATABASE", DB_LOGINID, DB_LOGIN_PASSWORD);
System.out.println("Connection Established");
return conn;
} catch (Exception ex) {
return null;
}
}
}
NOTE:
DATABASE – Name of the database
DB_LOGINID – Login Id for the data base
DB_LOGIN_PASSWORD – Login password for the data base
No comments:
Post a Comment