+ 2

Someone with knowledge in Android and SQL Server?

Someone who can help me with my problem please.. I treat to make a remote connection of android with SQL Server but I don't want use web service or any other method, just Android and SQL Server when I tried to make the connection, I received errors with the tcp and ip connection, but I corrected it, and also I had any others errors with the version of driver but I also corrected it, and there are several errors that I already corrected, the point here is that it doesn't let me make the connection!!!

5th Mar 2018, 11:35 PM
Edary Brizeth
Edary Brizeth - avatar
1 Réponse
0
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 import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import net.sourceforge.jtds.jdbc.*; public void query2() { Log.i("Android"," MySQL Connect Example."); Connection conn = null; try { String driver = "net.sourceforge.jtds.jdbc.Driver"; Class.forName(driver).newInstance(); //test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class; String connString = "jdbc:jtds:sqlserver://server_ip_address :1433/DBNAME;encrypt=fasle;user=xxxxxxxxx;password=xxxxxxxx;instance=SQLEXPRESS;"; String username = "xxxxxx"; String password = "xxxxxxxxxx"; conn = DriverManager.getConnection(connString,username,password); Log.w("Connection","open"); Statement stmt = conn.createStatement(); ResultSet reset = stmt.executeQuery("select * from TableName"); //Print the data to the console while(reset.next()){ Log.w("Data:",reset.getString(3)); // Log.w("Data",reset.getString(2)); } conn.close(); } catch (Exception e) { Log.w("Error connection","" + e.getMessage()); } } 4. You will find more about parameter passing here in connection string http://jtds.sourceforge.net/doc.html .
8th Mar 2018, 7:27 AM
Nandhini Gowthaman
Nandhini Gowthaman - avatar