我尝试连接
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/logins_db","root","")
但这是行不通的
我使用openserver,phpMyAdmin并使用Nox仿真器。
是的,我启用了互联网许可
TextView textView = findViewById(R.id.tv_connect_text);
String text="";
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e){
text += "We don't find your driver!";
e.printStackTrace();
text+=e.toString();
}
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/logins_db","root","");
}
catch (SQLException e){
e.printStackTrace();
text += "Connection failed!\n";
text +=e.toString()+"\n";
}
if(connection!=null){
text += "You are connect! Congratulate";
}
textView.setText(text);
结果:
连接失败! com.mysql.jdbc.exceptions.jdbc4.MySQLnonTranseitConnectionException: 无法建立与数据库服务器的连接。]
我知道有一个类似的问题,但是我想知道为什么应用程序找不到数据库?