Instructions below assumes you are using
Though things will work out other versions higher than this and possibly lower as well , its just to ensure a known state where things worked out.
So, once the JTDS is jar is download, first step is to include jar to your build path
Next, it seems like a bug, go to order and Export tab and enable jtds
Since the database connection operation is networked related, all network operations should be in different thread away from the main UI thread, so use AsyncTask.
Working code is can be downloaded from here , read the code, it is well documented.git@github.com:alkber/AndroidByExample.git
I can't get data from MSSQL2008 ....
ReplyDeleteI got error ' null '
it been a year right know lol , can you share with us the code about how to connect android to MSSQL2008 ?
Delete@Mohamed Brahen can you ask your doubts specifically from the above code ? The code is quite sefl explanatory. Please be free to ask.
DeleteThank you very much for the reply, i was asking about how to connect a file php to SQL SERVER 2008 I'd tried all the exemple but nothing happened ,this thing kill me
DeleteIts always better to make use of RESTApi to access your database contents, so that data access becomes transparent [hiding the connection details etc] . However for php case, i suppose your are talking to MSSQL server on the same server, ie php file and database on same machine.
Deletehttp://www.w3schools.com/php/php_mysql_connect.asp
This is as simple as explained in the above link.
My english isn't good enough to understand this article and I need this example I build an And. App but I need to connect my server who can help me abouth this
ReplyDeleteI have attached the JAR file with the application.. but still I am getting this error:
ReplyDelete06-18 18:43:00.572: I/System.out(9470): [CDS][DNS]Unable to resolve host "103": No address associated with hostname
06-18 18:43:00.573: I/com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask(9470): connecting failed
06-18 18:43:00.573: W/System.err(9470): java.sql.SQLException: Unknown server host name 'Host is unresolved: 103'.
06-18 18:43:00.584: W/System.err(9470): at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:427)
06-18 18:43:00.584: W/System.err(9470): at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
06-18 18:43:00.585: W/System.err(9470): at java.sql.DriverManager.getConnection(DriverManager.java:175)
06-18 18:43:00.585: W/System.err(9470): at java.sql.DriverManager.getConnection(DriverManager.java:209)
06-18 18:43:00.586: W/System.err(9470): at com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask.doInBackground(Dao.java:81)
06-18 18:43:00.586: W/System.err(9470): at com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask.doInBackground(Dao.java:1)
06-18 18:43:00.587: W/System.err(9470): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-18 18:43:00.588: W/System.err(9470): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-18 18:43:00.588: W/System.err(9470): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-18 18:43:00.590: W/System.err(9470): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-18 18:43:00.592: W/System.err(9470): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-18 18:43:00.592: W/System.err(9470): at java.lang.Thread.run(Thread.java:838)
06-18 18:43:00.593: W/System.err(9470): Caused by: java.net.UnknownHostException: Host is unresolved: 103
06-18 18:43:00.594: W/System.err(9470): at java.net.Socket.connect(Socket.java:836)
06-18 18:43:00.595: W/System.err(9470): at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)
06-18 18:43:00.596: W/System.err(9470): at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:251)
06-18 18:43:00.597: W/System.err(9470): at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:331)
06-18 18:43:00.597: W/System.err(9470): ... 11 more
06-18 18:43:00.597: E/com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask(9470): Unknown server host name 'Host is unresolved: 103'.
06-18 18:43:00.626: I/SurfaceTextureClient(9470): [STC::queueBuffer] (this:0x5279c278) fps:0.29, dur:3485.55, max:3485.55, min:3485.55
Can you please help..
I am trying out with your example but I am constantly getting this error:
ReplyDelete------------------------------------------------------------------------------------------------------
06-19 10:33:29.070: I/System.out(15447): [CDS][DNS]Unable to resolve host "103": No address associated with hostname
06-19 10:33:29.073: I/com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask(15447): connecting failed
06-19 10:33:29.074: W/System.err(15447): java.sql.SQLException: Unknown server host name 'Host is unresolved: 103'.
06-19 10:33:29.077: W/System.err(15447): at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:427)
06-19 10:33:29.077: W/System.err(15447): at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
06-19 10:33:29.077: W/System.err(15447): at java.sql.DriverManager.getConnection(DriverManager.java:175)
06-19 10:33:29.077: W/System.err(15447): at java.sql.DriverManager.getConnection(DriverManager.java:209)
06-19 10:33:29.077: W/System.err(15447): at com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask.doInBackground(Dao.java:81)
06-19 10:33:29.077: W/System.err(15447): at com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask.doInBackground(Dao.java:1)
06-19 10:33:29.078: W/System.err(15447): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-19 10:33:29.080: W/System.err(15447): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-19 10:33:29.080: W/System.err(15447): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-19 10:33:29.080: W/System.err(15447): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-19 10:33:29.080: W/System.err(15447): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-19 10:33:29.080: W/System.err(15447): at java.lang.Thread.run(Thread.java:838)
06-19 10:33:29.081: W/System.err(15447): Caused by: java.net.UnknownHostException: Host is unresolved: 103
06-19 10:33:29.082: W/System.err(15447): at java.net.Socket.connect(Socket.java:836)
06-19 10:33:29.082: W/System.err(15447): at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)
06-19 10:33:29.082: W/System.err(15447): at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:251)
06-19 10:33:29.082: W/System.err(15447): at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:331)
06-19 10:33:29.082: W/System.err(15447): ... 11 more
06-19 10:33:29.082: E/com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask(15447): Unknown server host name 'Host is unresolved: 103'.
---------------------------------------------------------------------------------------------------------------------
I think the JARfile is not getting connected with the
Try replacing your host name with ip address
DeleteI am trying out with your example but I am constantly getting this error:
ReplyDelete------------------------------------------------------------------------------------------------------
06-19 10:33:29.070: I/System.out(15447): [CDS][DNS]Unable to resolve host "103": No address associated with hostname
06-19 10:33:29.073: I/com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask(15447): connecting failed
06-19 10:33:29.074: W/System.err(15447): java.sql.SQLException: Unknown server host name 'Host is unresolved: 103'.
06-19 10:33:29.077: W/System.err(15447): at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:427)
06-19 10:33:29.077: W/System.err(15447): at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
06-19 10:33:29.077: W/System.err(15447): at java.sql.DriverManager.getConnection(DriverManager.java:175)
06-19 10:33:29.077: W/System.err(15447): at java.sql.DriverManager.getConnection(DriverManager.java:209)
06-19 10:33:29.077: W/System.err(15447): at com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask.doInBackground(Dao.java:81)
06-19 10:33:29.077: W/System.err(15447): at com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask.doInBackground(Dao.java:1)
06-19 10:33:29.078: W/System.err(15447): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-19 10:33:29.080: W/System.err(15447): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-19 10:33:29.080: W/System.err(15447): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-19 10:33:29.080: W/System.err(15447): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-19 10:33:29.080: W/System.err(15447): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-19 10:33:29.080: W/System.err(15447): at java.lang.Thread.run(Thread.java:838)
06-19 10:33:29.081: W/System.err(15447): Caused by: java.net.UnknownHostException: Host is unresolved: 103
06-19 10:33:29.082: W/System.err(15447): at java.net.Socket.connect(Socket.java:836)
06-19 10:33:29.082: W/System.err(15447): at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)
06-19 10:33:29.082: W/System.err(15447): at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:251)
06-19 10:33:29.082: W/System.err(15447): at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:331)
06-19 10:33:29.082: W/System.err(15447): ... 11 more
06-19 10:33:29.082: E/com.alkber.androidmssql2008.datastore.Dao$DBConnectionTask(15447): Unknown server host name 'Host is unresolved: 103'.
---------------------------------------------------------------------------------------------------------------------
I think the JARfile is not getting connected with the Application :(
Hi, I tried using your sample code but whenever I launch the application, the system keep giving me this error "Charset 0x0904000128/Cp850 is not supported by the JVM"I had tried connecting to the database in Java and it works fine but only in java android it gives me error . please help.
ReplyDeleteHello, I used your sample code, the code woking very well. I try to use dao.addUser(); function onclick button listener. the program doesnt work gives an error "unfortunely,the program has stopped".how can I solve this problem could you help please, thanks for sharing your interest.
ReplyDeleteButton b =(Button)findViewById(R.id.btn1);
b.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0) {
dao.addUser();
}
});
Note: dao.addUser(); function working well public void onConnectionSuccessful() { dao.addUser(); } but it doenst work on button click event.
Please show dao.addUser() code
ReplyDeleteKindly how to add login screen with dao.adduer like dao.checkuser()
Deletepublic void addUser(/* Some user info Model as parameter */) {
ReplyDeleteLog.i(LOG_TAG, "in adduser()");
if (conn == null) {
throw new InstantiationError(
"call Dao.connect(...) before calling Dao operations");
}
try {
Statement statement = conn.createStatement();
ResultSet rs = statement
.executeQuery("INSERT INTO user_info_table "
+ " VALUES ('1001', 'Bob', '333333', '33')");
rs.close();
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
Halo sir ,
ReplyDeleteI want to learn how to connect sql to my android app.I downloaded eg from "git clone git@github.com:alkber/AndroidByExample.git" but when i run the app i'm getting output as
attempting to connect to xx.xx.x....1433
with username :user
with password :password
I'm a beginner to android.
Halo sir ,
ReplyDeleteI want to learn how to connect sql to my android app.I downloaded eg from "git clone git@github.com:alkber/AndroidByExample.git" but when i run the app i'm getting output as
attempting to connect to xx.xx.x....1433
with username :user
with password :password
I'm a beginner to android.