-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBConnection.java
80 lines (71 loc) · 2.14 KB
/
DBConnection.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
// Definition of class DBConnection - Establish connection to the database
// Author: Siomara Pantarotto
// File : DBConnection.java
// Date : June,8,2000
import java.sql.*;
public class DBConnection
{
private Connection conn;
private Statement stmt;
private String driver = "oracle.jdbc.driver.OracleDriver";
// Parameters for Local Oracle8i Server
private String url = "jdbc:oracle:thin:@PROKIDS:1521:ORCL";
private String user = "INTERNAL";
private String password = "oracle";
/////////////////////////////////////////////////////////////////////////
// Constructor - Establish connection to the database
//
public DBConnection()
{
try {
Class.forName(driver);
}
catch(Exception e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement();
}
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
///////////////////////////////////////////////////////////////////////////
// Return connection object
//
public Connection getConnection() {
return conn;
}
///////////////////////////////////////////////////////////////////////////
// Return statement object
//
public Statement getStatement() {
return stmt;
}
///////////////////////////////////////////////////////////////////////////
// Close DB connection
//
public void closeConnection() {
try {
conn.close();
}
catch(Exception e) {
System.err.print("Unable to disconect");
e.printStackTrace();
}
}
/////////////////////////////////////////////////////////////////////////
// Close statement object
//
public void closeStatement() {
try {
stmt.close();
}
catch(Exception e) {
System.err.print("Unable to close statement");
e.printStackTrace();
}
}
}