-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbConnection.java
More file actions
24 lines (23 loc) · 912 Bytes
/
Copy pathDbConnection.java
File metadata and controls
24 lines (23 loc) · 912 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
import java.sql.*;
/*
* DbConnection class is used to connect to the mysql database which is located
* in the localhost.It has getConnection() method to load the driver,getDbConnection()
* method to connect to the database in the localhost and closeConnection() method
* to close the database connection .
*/
public class DbConnection {
private Connection con=null;
private String user="root";
private String pass="";
private String db="jdbc:mysql://localhost:3306/examinationsystem";
public void getConnection() throws ClassNotFoundException, InstantiationException, IllegalAccessException{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
public Connection getDbConnection() throws SQLException{
con=DriverManager.getConnection(db,user,pass);
return (Connection) con;
}
public void closeConnection() throws SQLException{
con.close();
}
}