-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLInteractor.java
executable file
·96 lines (92 loc) · 2.89 KB
/
SQLInteractor.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
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
94
95
96
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Date;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.microsoft.sqlserver.jdbc.*;
class status1 {
srvInfo item;
SQLInteractor writer;
public status1(SQLInteractor sqli) {
item = new srvInfo();
writer=sqli;
}
@Subscribe
public void recvStatus(srvInfo in){
item = in;
item.toString();
writer.write(item);
}
}
public class SQLInteractor implements Runnable {
Connection con;
EventBus eb;
public SQLInteractor(EventBus commands) {
eb = commands;
eb.register(new status1(this));
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String connectionUrl = "jdbc:sqlserver://127.0.0.1:1433;" +
"databaseName=CTFData;user=ctfgrd;password=REDACTED;";
try {
con = DriverManager.getConnection(connectionUrl);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void run() {
// TODO Auto-generated method stub
}
public void write(srvInfo item){
Statement stmt = null;
Timestamp dateTime = null;
Timestamp correctDateTime=null;
try{
dateTime = new Timestamp(item.dateTime_d.getTime());
} catch (Exception e){
dateTime = new Timestamp(new Date().getTime());
}
try {
correctDateTime = new Timestamp(item.correctDateTime_d.getTime());
} catch (Exception e) {
correctDateTime = new Timestamp(new Date().getTime());
}
try {
stmt = con.createStatement();
String cmd = "INSERT INTO ctf_data "+
"(ServerAddress,ServerName,HostName,"+
"UserClaimedServerName,ClaimedDate,CorrectDate,"+
"isReachable,HTTPUp,HTTPStatus,WebServer,"
+"poweredBy) VALUES ('"+ item.serverAddress +"','"
+item.serverName+"','"+item.hostName+"','"+
item.claimedHostName+"',"+dateTime+","+
correctDateTime+","+item.isReachable+","+
item.HTTPWorking+","+item.httpStatusCode+",'"+
item.websrv+"','"+item.poweredBy+"')";
System.out.println("cmd: " + cmd);
stmt.executeUpdate("INSERT INTO ctf_data "+
"(ServerAddress,ServerName,HostName,"+
"UserClaimedServerName,ClaimedDate,CorrectDate,"+
"isReachable,HTTPUp,HTTPStatus,WebServer,"
+"poweredBy) VALUES ('"+ item.serverAddress +"','"
+item.serverName+"','"+item.hostName+"','"+
item.claimedHostName+"','"+dateTime+"','"+
correctDateTime+"','"+item.isReachable+"','"+
item.HTTPWorking+"',"+item.httpStatusCode+",'"+
item.websrv+"','"+item.poweredBy+"')");
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}