-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFact.java
More file actions
93 lines (73 loc) · 2.15 KB
/
Fact.java
File metadata and controls
93 lines (73 loc) · 2.15 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
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
90
91
92
93
import java. sql. * ;
public class Fact {
public Connection makeConnection()
throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new SQLException("Unable to load driver class"); }
return DriverManager.getConnection("com.mysql.jdbc.Driver");
}
public Connection makeConnection(String URL)
throws SQLException {
return DriverManager. getConnection(URL) ;
}
public Connection makeConnection(String DriverName, String URL)
throws SQLException {
try {
Class.forName(DriverName);
} catch (ClassNotFoundException e) {
throw new SQLException("Unable to load driver class"); }
return DriverManager.getConnection(URL);
public Connection makeConnection(String URL, String username,String password)
throws SQLException {
return DriverManager. getConnection(URL, username, password) ;
}
public Connection makeConnection(String DriverName, String URL,String username, String password)
throws SQLException {
try {
Class.forName(DriverName);
} catch (ClassNotFoundException e) {
throw new SQLException("Unable to load driver class");
}
return DriverManager.getConnection(URL,username,password);
public void closeConnection(Connection c, Statement s)
{
try {
if (s != null) s.close();
if (c != null) c.close();
} catch (SQLException sqlex) {}
}
// my name is rahul
public static void main(String args[]) {
Fact CJ = new Fact();
Connection dbConnect = null;
Statement dbStatement = null;
try {
switch (args.length) {
case 0 : dbConnect = CJ.makeConnection();
break;
case 1 : dbConnect = CJ.makeConnection(args[O]);
break;
case 2 : dbConnect = CJ.makeConnection(args[O],args[l]);
break;
case 3 : dbConnect = CJ.makeConnection(args[O],args[l],args[2]);
break;
case 4 : dbConnect = CJ.makeConnection(args[O],args[l],args[2],args[3]);
break;
default :
System.out.println("Using the default driver");
dbConnect = CJ.makeConnection();
}
System.out.println("Made a connection!");
dbStatement = dbConnect.createStatement();
System.out.println("Made a statement!");
} catch (SQLException sqlex) {
System.out.println(sqlex.getMessage());
}
finally {
CJ.closeConnection(dbConnect,dbStatement);
System.out.println("Closed the connection.");
}
}
}