1 |
package tools; |
2 |
|
3 |
import java.sql.SQLException; |
4 |
|
5 |
public class QueryThread extends Thread { |
6 |
|
7 |
String query; |
8 |
String host; |
9 |
String user; |
10 |
String pwd; |
11 |
String db; |
12 |
|
13 |
public QueryThread(String query, String host, String user, String pwd, String db){ |
14 |
this.query = query; |
15 |
this.host = host; |
16 |
this.user = user; |
17 |
this.pwd = pwd; |
18 |
this.db = db; |
19 |
start(); |
20 |
} |
21 |
|
22 |
public QueryThread(String query, MySQLConnection conn){ |
23 |
this.query = query; |
24 |
this.host = conn.getHost(); |
25 |
this.user = conn.getUser(); |
26 |
this.pwd = conn.getPassword(); |
27 |
this.db = conn.getDbname(); |
28 |
start(); |
29 |
} |
30 |
|
31 |
public void run(){ |
32 |
try { |
33 |
long start = System.currentTimeMillis(); |
34 |
MySQLConnection conn = new MySQLConnection(host,user,pwd,db); |
35 |
conn.executeSql(query); |
36 |
conn.close(); |
37 |
long end = System.currentTimeMillis(); |
38 |
System.out.println("Executed QUERY="+query+" DB="+db+", HOST="+host+". Time was: "+(end-start)/1000+" seconds."); |
39 |
} |
40 |
catch(SQLException e){ |
41 |
e.printStackTrace(); |
42 |
System.err.println("Couldn't execute QUERY="+query+" DB="+db+", HOST="+host); |
43 |
} |
44 |
} |
45 |
|
46 |
} |