I am having lots of trouble with sending basic data to a sql database from an android app that I have developed. I have a basic connection class, and then what I believe to be a very simple query that should occur on a button click like....
public void onUploadTest(View v) {
try{
Connection con = connectionClass.Conn();
String query = "INSERT INTO photo (photoID, userID, date, title, description, location, selected) VALUES ("
+ 100 + ", "
+ 2 + ", "
+ "4/17/2018" + ", "
+ "awesome" + ", "
+ "yeppp" + ", "
+ "google.com" + ", "
+ 1
+ ");";
Statement stmt = con.createStatement();
stmt.execute(query);
con.close();
} catch(SQLException e) {
Log.d("sql", e.toString());
} catch(IllegalStateException e) {
Log.d("sql", e.toString());
}
}
but not matter what I try I keep getting an IllegalStateException that points back to `the line with 'con.createStatement();' My connection class
public class ConnectionClass {
String ip = "206.212.36.194";
String db = "DroneInspDB";
String un = "aksenov";
String password = "Datapass123";
//String ConnURL = null;
@SuppressLint("NewApi")
public Connection Conn() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
//String ConnURL = null;
try {
Class.forName("net.sourceforge.jtds.jdbs.Driver");
String ConnURL = "jdbc:jtds:sqlserver://" + db + ";user=" + un + ";password=" + password + ";";
conn = DriverManager.getConnection(ConnURL);
} catch(SQLException se) {
Log.d("sql ", se.toString());
} catch(ClassNotFoundException e) {
Log.d("sql ", e.toString());
} catch(NullPointerException e) {
Log.d("sql", e.toString());
} catch(Exception e){
Log.d("sql ", e.toString());
}
return conn;
}
}