package targetfinder;
import java.io.*;
import java.sql.*;
public class addToDB extends Thread {
private String type, Name, Island, Kingdom, Value;
private int Race;
public addToDB(String type, String Name, String Island, String Kingdom, int Race, String Value) {
this.type=type; this.Name=Name; this.Island=Island; this.Kingdom=Kingdom; this.Race=Race; this.Value=Value;
}
public void run() { // throws SQLException, UnsupportedEncodingException, IOException
//update database
//Database connection
try {
Class.forName(\"org.gjt.mm.mysql.Driver\");
} catch(java.lang.ClassNotFoundException e) {
System.out.println(\"ClassNotFoundException: \"+e.getMessage());
}
try {
Connection con = DriverManager.getConnection(\"jdbc:
mysql://mysql.kellberg.com:3306/kellberg?user=*&password=*\");
Statement stmt = con.createStatement();
String SQL=\"SELECT * FROM Province WHERE Name=\'\"+Name+\"\'\";
ResultSet RS = stmt.executeQuery(SQL);
String SQL2=\"\";
if (RS.next()) {
SQL2 = \"UPDATE Province SET \"+type+\"=\"+Value+\", Island=\"+Island+\", Kingdom=\"+Kingdom+\", Updated=1 WHERE Name=\'\"+Name+\"\'\";
}
else {
SQL2 = \"INSERT INTO Province SET Name=\'\"+Name+\"\', Island=\"+Island+\", Kingdom=\"+Kingdom+\", \"+type+\"=\"+Value+\", Race=\"+Race+\", Updated=1\";
}
RS.close();
//ResultSet RS2 = stmt.executeQuery(SQL2);
stmt.executeUpdate(SQL2);
stmt.close();
con.close();
RS = null;
stmt = null;
con = null;
//RS2.close();
//System.out.println(Name+\"\'s thread done\");
} catch (Exception e) {
System.out.println(\"\\nException: \"+e.getMessage());
e.printStackTrace();
}
}
}