-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectionProvider.java
33 lines (27 loc) · 1.02 KB
/
ConnectionProvider.java
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
// Class for provide the connection with the database..
/*
By the using of this class we don't need to write the whole code that is given in every class.
We can use this class in any class for creating connection with database. We only need to use
this class name or function name for create connection with database.
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class ConnectionProvider {
private static Connection con;
public static Connection getConnection(){
try{
if(con == null){
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/employee?characterEncoding=latin1";
String username = "root";
String pass = "root9771";
con = DriverManager.getConnection(url,username,pass);
}
}
catch (Exception e){
e.printStackTrace();
}
return con;
}
}