Reputation: 11
I am trying to connect my Android device to MySQL DB which is running on MySQL Server. But I keep getting the error stated below.
Can anyone please point me in the right direction here?
LOGCAT
07-15 09:17:21.708: E/AndroidRuntime(19677): FATAL EXCEPTION: AsyncTask #1
07-15 09:17:21.708: E/AndroidRuntime(19677): java.lang.RuntimeException: An error occured while executing doInBackground()
07-15 09:17:21.708: E/AndroidRuntime(19677): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
07-15 09:17:21.708: E/AndroidRuntime(19677): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.lang.Thread.run(Thread.java:841)
07-15 09:17:21.708: E/AndroidRuntime(19677): Caused by: java.lang.VerifyError: net/sourceforge/jtds/jdbc/TdsCore
07-15 09:17:21.708: E/AndroidRuntime(19677): at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:359)
07-15 09:17:21.708: E/AndroidRuntime(19677): at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.sql.DriverManager.getConnection(DriverManager.java:179)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.sql.DriverManager.getConnection(DriverManager.java:213)
07-15 09:17:21.708: E/AndroidRuntime(19677): at com.example.rf.MainActivity.runSQL(MainActivity.java:110)
07-15 09:17:21.708: E/AndroidRuntime(19677): at com.example.rf.MainActivity$DoInBackground.doInBackground(MainActivity.java:58)
07-15 09:17:21.708: E/AndroidRuntime(19677): at com.example.rf.MainActivity$DoInBackground.doInBackground(MainActivity.java:1)
07-15 09:17:21.708: E/AndroidRuntime(19677): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-15 09:17:21.708: E/AndroidRuntime(19677): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-15 09:17:21.708: E/AndroidRuntime(19677): ... 4 more
CODE
How I call it:
new DoInBackground().execute();
The methods:
private class DoInBackground extends AsyncTask<Void, Void, Void>
{
@Override
protected Void doInBackground(Void...unused) {
String response = "";
try {
runSQL();
}
catch(Exception e) {
Log.i("Error", e.toString());
}
return null;
}
}
public void runSQL()
{
String connectionString = "jdbc:jtds:sqlserver://server:1433/DBNAME;instance=SQLEXPRESS";
String userName = "username";
String password = "password";
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver"); //specify the jtds driver
Connection conn = DriverManager.getConnection(connectionString, userName, password); //establish connection
//System.out.println("Connection properly established");
Log.i("Success", "Connected to DB");
conn.close();
} catch (Exception e)
{
String err = (e.getMessage()==null)?"SD Card failed":e.getMessage();
Log.e("sdcard-err2:",err);
}
}
UPDATE
I have found the problem. The problem was, I was using ktds 1.3.1 as the driver to connect to the DB, but this version is bugged. So switching back to 1.3.0 version solved my problems.
Thanks for all the help!
Upvotes: 0
Views: 772
Reputation: 9904
I assume that you are trying to connect your server's SQL from android client. You cannot directly connect to SQL server from android client. You need to create web-services at your server end for it.
Inside the web-service, you can use appropriate JDBC Connections..
Upvotes: 1