1

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");
}

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

can you provide a sample code or link to any basic connectivity with MySQL?
But can we connect without using PHP?
@Himanshu refer this link to create json 9lessons.info/2012/08/java-json-jquery-display-records.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.