-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBConnection.java
More file actions
40 lines (28 loc) · 1.36 KB
/
DBConnection.java
File metadata and controls
40 lines (28 loc) · 1.36 KB
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
//*****************************************************************
// DBconnection.java Author: Ravyar Sarbast
//
// a main connection to database
//*****************************************************************
package RavyarSarbastTahir;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
Connection conncetion;
public DBConnection() throws SQLException, ClassNotFoundException, IOException, SAXException, ParserConfigurationException {
String[] login = new XMLFile().read();
String url = "jdbc:mysql://" +login[3]+ ":"+ login[4]+"/" +login[2];// making connection to the database from setting read from xml file
String user = login[0];
String password = login[1];
//login detail for MySQL or MariaDB
Class.forName("org.mariadb.jdbc.Driver");//Maria DB Driver can be replaced with MySQL driver
conncetion = DriverManager.getConnection(url, user, password);//connecting to data
conncetion.setAutoCommit(false);// disabling auto commit so I it false happen it roll back to older state
}
Connection getConncetion() {
return conncetion;
}// method to connect to database from other objects
}