Simple JDBC Connection code in java
This post is to get the simple JDBC connection in java.
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/DataBase_Name";
// Database credentials
static final String USER = "admin";
static final String PASS = "admin";
public Connection conn = null;
/**
* This Method will return the Database Connection
*/
public Connection getDbConnection()
{
try{
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL,USER,PASS);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch(SQLException se){
}
return conn;
}
This post is to get the simple JDBC connection in java.
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/DataBase_Name";
// Database credentials
static final String USER = "admin";
static final String PASS = "admin";
public Connection conn = null;
/**
* This Method will return the Database Connection
*/
public Connection getDbConnection()
{
try{
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL,USER,PASS);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch(SQLException se){
}
return conn;
}
No comments:
Post a Comment