I've followed this tutorial: http://www.parallelcodes.com/connect-android-to-ms-sql-database-2/
So Im using jtds-1.2.7.jar on Android Studio in trying to connect my app to an external MySQL server, 000webhost to be specific.
I keep getting this error:
E/SQL Exception: I/O Error: Unknown packet type 0x46
Here's the code:
import android.os.StrictMode;
import android.util.Log;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
public class SQLConnection {
String ip = "sql12.000webhost.com:3306";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "db_name";
String un = "username";
String password = "password";
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName(classs);
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("SQL Exception", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("Class Not Found", e.getMessage());
} catch (Exception e) {
Log.e("Exception", e.getMessage());
}
return conn;
}
}
Any help is much appreciated!
Thank you very much!
Cheers!