我已按照本教程:here
所以我在Android Studio上使用jtds-1.2.7.jar尝试将我的应用程序连接到外部MySQL服务器,000webhost是具体的。
我一直收到这个错误:
E / SQL异常:I / O错误:未知数据包类型0x46
以下是代码:
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;
}
}
非常感谢任何帮助!
非常感谢!
干杯!