-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.java
89 lines (69 loc) · 2.09 KB
/
Database.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package AIM;
import java.sql.*;
class Database{
final static String Database_Name="user";
final static private String url="jdbc:mysql://localhost:3306/pavan";
final static private String uname="root";
final static private String pass="Pavan@161103";
private String query;
private Statement st;
private PreparedStatement pst;
private Connection con;
public void setCon(Connection con) {
this.con = con;
}
public Connection getCon() {
return con;
}
public void setSt(Statement st) {
this.st = st;
}
public Statement getSt() {
return st;
}
public void setPst(PreparedStatement pst) {
this.pst = pst;
}
public PreparedStatement getPst() {
return pst;
}
public void setQuery(String query) {
this.query = query;
}
public String getQuery() {
return query;
}
final public void Establish() throws Exception
{
//Class.forName("com.mysql.jdbc.Driver");
setCon(DriverManager.getConnection(url,uname,pass));
setSt(getCon().createStatement());
return;
}
final public ResultSet Execute() throws SQLException
{
return getSt().executeQuery(getQuery());
}
final public int Update() throws SQLException
{
return getSt().executeUpdate(getQuery());
}
//method overload for prepared statement
final public ResultSet Establish(String Table_Name) throws Exception
{
//Class.forName("com.mysql.jdbc.Driver");
setCon(DriverManager.getConnection(url,uname,pass));
setPst(getCon().prepareStatement(getQuery()));
complete_prepared_statement(Table_Name);
return getPst().executeQuery();
}
public void complete_prepared_statement(String Table_Name) throws SQLException
{
getPst().setString(1,Table_Name);
}
final public void Close(Statement st,Connection con) throws SQLException
{
st.close();
con.close();
}
}