Reputation: 57
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");
}
Upvotes: 1
Views: 290
Reputation: 12042
Use the Webservice
to make the Connection to Mysql from your android app through json or xml.you can use SQlite
database to connect the android app internally by the use of this package android.database.sqlite classes
Upvotes: 1