Connect to a SQL Database

by AntoniMG » Wed, 08 Jul 2009 01:02:43 GMT


Sponsored Links
 Hi,

Im triying to connect to a SQL Database with Android, this is my code:

package com.example.conversor;
import java.sql.*;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

[...]

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (Exception e) {
e.printStackTrace();
}


try {
DBConnSQL = DriverManager.getConnection("jdbc:sqlserver://zeus:
1433;DatabaseName=dsnew;","sa","sapass");
} catch (Exception e)
{
e.printStackTrace();
}

And this is what i get:

07-07 11:16:27.450: ERROR/jdwp(1597): Failed sending reply to
debugger: Broken pipe
07-07 11:16:29.832: ERROR/dalvikvm(1605): Could not find class
'javax.sql.XAConnection', referenced from method
com.microsoft.sqlserver.jdbc.SQLServerConnection.close
07-07 11:16:29.931: ERROR/AndroidRuntime(1605): Uncaught handler:
thread main exiting due to uncaught exception
07-07 11:16:29.983: ERROR/AndroidRuntime(1605): java.lang.VerifyError:
com.microsoft.sqlserver.jdbc.SQLServerConnection
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
java.sql.DriverManager.getConnection(DriverManager.java:192)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
java.sql.DriverManager.getConnection(DriverManager.java:228)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
com.example.conversor.ConversorAct.onCreate(ConversorAct.java:39)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
android.os.Handler.dispatchMessage(Handler.java:99)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
android.os.Looper.loop(Looper.java:123)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
java.lang.reflect.Method.invokeNative(Native Method)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
java.lang.reflect.Method.invoke(Method.java:521)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
07-07 11:16:29.983: ERROR/AndroidRuntime(1605):     at
dalvik.system.NativeStart.main(Native Method)



SQL Server is correctly installaed and configured, and receiving
Querys from other app.

Thanks.




--~--~---------~--~----~------------~-------~--~----~



Connect to a SQL Database

by Charlie Collins » Wed, 08 Jul 2009 04:06:08 GMT


 n general you don't want to do that - connect directly to your SQL
server from Android. If your Android device is on the same subnet,
and you configure host resolution and port access, you *might* be able
to do that, I have never really thought to try, but it's certainly not
the normal path.

Normally, you will want a server side API, like REST or such, that you
can call from Android using HTTP or something. That way your device
can connect to your server side API and it doesn't need to know
anything about it being a SQLServer (the abstraction is at a different
level), and it will work regardless of whether or not you are on the
same subnet. Have a look at a REST implementation for your favorite
server side language (Jersey for Java, whatever for .net, etc) and
create a simple server side for your Android app to connect to, and
try that.

On Jul 7, 7:18am, AntoniMG <tonio...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. CLOSE_WAIT status never clears

I am using the HttpURLConnection class to make my http requests to get
data and I am noticing that some OS tools show my app as remaining in
a CLOSE_WAIT status no matter how long I wait.  Here is a sample of
the code I use to make the request,

            URL url = new URL(strURL);
            URLConnection connection = url.openConnection();
            HttpURLConnection httpConnection =
(HttpURLConnection)connection;
            httpConnection.setDoInput(true);
            httpConnection.setDoOutput(true);
            httpConnection.setUseCaches(false);
            httpConnection.setRequestMethod(GET);

            int responsecode = httpConnection.getResponseCode();
            if (responsecode == HttpURLConnection.HTTP_OK) {
                InputStream in = httpConnection.getInputStream();

                byte[] buffer = new byte[bufSize];
                int bufSize = 8192;
                int length = bufSize;
                while (length != -1) {
                    // keep reading until we get -1 returned...
                    length = in.read(buffer, 0, bufSize);
                }
            }

            in.close();
            httpConnection.disconnect();


Is this a known issue with the platform or am I missing a step in
closing the connection?

Thanks, Mark

-- 

2. android emulator touch driver

Hi
Can someone help me to solve following questions in understanding how
touch events are emulated in Android Emulator ?

1. Mouse events are used as touch events.
2. But, I am not able to find any "goldfish_mouse*.c" file in
emulator/
goldfish kernel.


3. If there is no such file, who creates /dev/input/event0 device on
emulator ? Is it drivers/input/keyboard/goldfish-events.c file ? If
yes, I do not see any code related to sending touch events like
input_report_abs(,,,)?


Thanks,
Viral

PS - I also posted the same message on android-platform. But, it looks
more relevant here though it is regarding emulated kernel.

-- 

3. How to check the state of an activity and buttons(for selector : res/Drawable)

4. Hello. I try to contribute when I can so please help me on an a Bitmap issue if possible.

5. Porting to FPGA

6. Preference data types

7. Opaque Binary Blob (OBB)?