-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.java
58 lines (50 loc) · 1.75 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
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class Database implements IConnection
{
public Connection connection = null;
public Statement stmt = null;
public Database(String connStr) throws Exception
{
this.connection = DriverManager.getConnection(connStr);
this.stmt = this.connection.createStatement();
}
@Override
public void executeQuery(String query, String type) throws Exception
{
int iTimeout = 30;
String sMakeTable = "CREATE TABLE IF NOT EXISTS rssfeeds (date text, author text, category text, link text, title text, UNIQUE(title))";
String sMakeInsert = "";
String sMakeSelect = "";
if(type.equals("insert"))
sMakeInsert = query;
if(type.equals("select"))
sMakeSelect = query;
try {
try {
stmt.setQueryTimeout(iTimeout);
stmt.executeUpdate( sMakeTable );
if(type.equals("insert"))
stmt.executeUpdate( sMakeInsert );
if(type.equals("select")){
ResultSet rs = stmt.executeQuery(sMakeSelect);
try {
while(rs.next())
{
String sResult = rs.getString("title");
System.out.println(sResult);
}
} finally {
try { rs.close(); } catch (Exception ignore) {}
}
}
} finally {
try {} catch (Exception ignore) {}
}
} finally {
try {} catch (Exception ignore) {}
}
}
}