Recently I have tried to connect to SQL Database server which is in my local network machine. I can connect and access SQL server from my Android app. I did it in the following way….
1. First of all you need a JDBC driver library for SQL Server. As we know android library has only SQLite database driver. So first download an open source JDBC driver from this
http://jtds.sourceforge.net/ site (I downloaded the Linux version).
2. Then import the jar file into your Android app.(jtds-1.2.5.jar).
3. Now just try this code by modifying according to your context
01 | import java.sql.Connection; |
02 | import java.sql.DriverManager; |
03 | import java.sql.ResultSet; |
04 | import java.sql.Statement; |
06 | import net.sourceforge.jtds.jdbc.*; |
10 | Log.i( "Android" , " MySQL Connect Example." ); |
11 | Connection conn = null ; |
13 | String driver = "net.sourceforge.jtds.jdbc.Driver" ; |
14 | Class.forName(driver).newInstance(); |
16 | String connString = "jdbc:jtds:sqlserver://server_ip_address:1433/DBNAME;encrypt=fasle;user=xxxxxxxxx;
password=xxxxxxxx;instance=SQLEXPRESS;" ; |
17 | String username = "xxxxxx" ; |
18 | String password = "xxxxxxxxxx" ; |
19 | conn = DriverManager.getConnection(connString,username,password); |
20 | Log.w( "Connection" , "open" ); |
21 | Statement stmt = conn.createStatement(); |
22 | ResultSet reset = stmt.executeQuery( "select * from TableName" ); |
26 | Log.w( "Data:" ,reset.getString( 3 )); |
33 | Log.w( "Error connection" , "" + e.getMessage()); |
HI so should String driver = the URL you have?
ReplyDeleteand what should String connString be equal to? May be clearer if rather than putting in what you use you type in exactly what should be there, eg yourUserNameGoesHere
There's a library available now from http://www.dattrax.com/datasync that does one-way and two-way replication both online and offline with SQL Server. Might be worth checking it out.
ReplyDeleteTry this post :
ReplyDeletehttp://www.parallelcodes.com/connect-android-to-ms-sql-database/[^]
SMM PANEL
ReplyDeletesmm panel
İs İlanlari Blog
İNSTAGRAM TAKİPÇİ SATIN AL
https://www.hirdavatciburada.com/
beyazesyateknikservisi.com.tr
SERVİS
tiktok jeton hilesi