我正在尝试从android studio连接到mysql服务器。我已经将mysql连接器jar文件添加到项目和classpath环境变量中。一切编译正常,但在运行时出现以下错误:
Rejecting re-init on previously-failed class java.lang.Class<com.mysql.cj.MysqlType>:
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/sql/SQLType;
这是代码:
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://sql2.freemysqlhosting.net:3306/sql2303751",user,pass);
运行时错误发生在con = DriverManager.getConnection(...)
行中,因此驱动程序已正确设置,表明jar文件已正确添加到项目中。
预先感谢
答案 0 :(得分:0)
您可以尝试这个希望对您有帮助的
这是我的网址
// change the url and try to add http or https before the url
String url = "jdbc:mysql://xxx.xx.xx.xxx:3306/myDatabase";
//my codes to connect
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Class.forName(classs);
conn = DriverManager.getConnection(url , username, password);