-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectAccess.java
64 lines (53 loc) · 1.8 KB
/
ConnectAccess.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
import java.sql.*;
public class ConnectAccess {
private Connection conn;
private Statement stmt;
public void CloseAccessFile() throws Exception
{
stmt.close();
conn.close();
}
public void OpenAccessFile() throws Exception
{
Class.forName("com.hxtt.sql.access.AccessDriver");
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String path = this.getClass().getClassLoader().getResource("MyDB.mdb").getPath().substring(1);
String url="jdbc:Access:///"+path;
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
}
public boolean GetUserMsg(Account account) throws Exception
{
int rowcount =0;
String strsql="";
strsql +="select * from Account where [name]='" + account.verifyid+"' and password ='"+account.password+"'";
ResultSet rs = stmt.executeQuery(strsql);
while (rs.next())
{
account.verifyid=rs.getString(1);
account.password=rs.getString(2);
account.level=rs.getString(3);
account.author=rs.getString(4);
rowcount++;
}
rs.close();
return rowcount>0?true:false;
}
public ResultSet GetSet(String str) throws Exception
{
ResultSet rs = stmt.executeQuery(str);
return rs;
}
public boolean SaveMsg(String str) throws Exception
{
int rowcount =0;
rowcount = stmt.executeUpdate(str);
return rowcount>0?true:false;
}
public boolean UpdateMsg(String str) throws Exception
{
int rowcount =0;
rowcount = stmt.executeUpdate(str);
return rowcount>0?true:false;
}
}