I'm trying to connect my android app with an online database server that uses MySQL
and phpMyAdmin
.
But problem I am having is that I'm unable to access my database (which is online) using Java code for android.
It get the following error:
java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection(DriverManager.java:187)
I already loaded the driver and external JAR of MySQL but it is still showing this exception.
The code is :
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection(
"jdbc:mysql:http://www.demo.com:2082/",
"usernme", "password"); //username and password of cpanel access
PreparedStatement statement = con
.prepareStatement("SELECT * FROM users WHERE userName = '"
+ userName + "'");
ResultSet result = statement.executeQuery();
while (result.next()) {
retrievedUserName = result.getString("username");
Log.e("data username:", retrievedUserName);
retrievedPassword = result.getString("password");
}
使用Webservice
,使您的Android应用通过JSON连接到MySQL或xml.you可以使用SQlite
数据库,通过使用这个包的内部连接的Android应用android.database.sqlite classes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.