forked from internsathi/Java-Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBConnectionUtil.java
More file actions
40 lines (30 loc) · 858 Bytes
/
DBConnectionUtil.java
File metadata and controls
40 lines (30 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.classes.util;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnectionUtil {
//define the database property
public static final String URL="jdbc:mysql://localhost:4000/pspa";
public static final String DRIVER="com.mysql.jdbc.Driver";
public static final String USERNAME="root";
public static final String PASSWORD="";
public static Connection connection=null;
//define static method
public static Connection openConnection()
{
//check the connection
if(connection !=null) {
return connection;
}else {
try {
//load the driver
Class.forName(DRIVER);
//GET THE CONNECTION
connection=DriverManager.getConnection(URL,USERNAME,PASSWORD);
}catch(Exception e)
{
e.printStackTrace();
}
}
return connection;
}
}