我想将我的android项目连接到mysql JDBC上的我的数据库..我正在使用wampserver ...当我运行程序时我有这个错误
Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo
W/System.err: java.sql.SQLException: null, message from server: "Host 'widy-PC' is not allowed to connect to this MySQL server"
这是我的代码
public class Conexion {
String classs = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/sanz";
String un = "root";
String password = "Kamasutra,27";
@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(classs).newInstance();
conn = DriverManager.getConnection(url, un, password);
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
}
如果有人能帮助我,那将非常有用,非常感谢
答案 0 :(得分:0)
我建议您的应用直接与数据库通信,您应该创建一个网络服务API来发送和接收从您的移动应用到Web服务API的数据。