I am new to jdbc and android. So pardon me if the question seems silly.
I am trying to connect to a MySql database from an app.
I went through the jdbc tutorial and wrote the following code:
public static void connectToServer ()
{
Connection conn = null;
try
{
//Connect to the database
String userName = "********";
String password = "********";
String url = "jdbc:mysql://my.domain.name/myDBname";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
Log.e(tag,"Database connection established");
// Query the database
Statement s = conn.createStatement ();
String query = "INSERT INTO myTableName (A,B,C)" +
"VALUES ('a','b','c')");
Log.e(tag,query);
s.executeQuery (query);
s.close ();
}
catch (Exception e)
{
Log.e(tag,"Database Connection Failed");
Log.e(tag,e.getMessage());
}
finally
{
if (conn != null)
{
try
{
conn.close ();
Log.e(tag,"Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
My manifest code:
< uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
< uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
The logcat is:
....
Database connection terminated //my output
com.mysql.jdbc.Driver // output from exception e.getMessage()
What am I doing wrong?
Is there a difference between connecting from a java application and android app?
EDIT : Added manifest permissions