forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBean1.java
More file actions
93 lines (89 loc) · 1.74 KB
/
Bean1.java
File metadata and controls
93 lines (89 loc) · 1.74 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
package cars;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Bean1 {
Connection con;
Statement st;
ResultSet rs;
String name;
int i;
boolean bln;
public Bean1() {
}
public synchronized Connection getcon() throws Exception {
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=db_Cars","sa","");
return con;
}
catch(Exception ex){
ex.printStackTrace();
}
return null;
}
public Statement getst(){
try{
con=getcon();
st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
return st;
}
catch(Exception e1){
}
return null;
}
public ResultSet getrs(String sql){
try{
st=getst();
rs=st.executeQuery(sql);
return rs;
}
catch(Exception e2){
}
return null;
}
public int getint(String sql){
try{
st=getst();
i=st.executeUpdate(sql);
return i;
}
catch(Exception e3){
}
return 0;
}
public boolean getbln(String sql){
try{
st=getst();
bln=st.execute(sql);
return bln;
}
catch(Exception e4){
}
return false;
}
public synchronized void close(){
try{
if(rs!=null){
rs.close();
rs = null;
}
if(st!=null){
st.close();
st = null;
}
if(con!=null){
con.close();
con = null;
}
}
catch(Exception e5){
}
}
}