Hi,
I need code of connectivity between android and sql server. Please help.. Its important.
Thanks in advance!
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Joginder BangerPosted Sep 12, 2015, 1:24 AM
importjava.sql.Connection;02importjava.sql.DriverManager;03importjava.sql.ResultSet;04importjava.sql.Statement;0506importnet.sourceforge.jtds.jdbc.*;0708publicvoidquery2()09{10Log.i("Android"," MySQL Connect Example.");11Connection conn =null;12try{13String driver ="net.sourceforge.jtds.jdbc.Driver";14Class.forName(driver).newInstance();15//test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;16String connString ="jdbc:jtds:sqlserver://server_ip_address:1433/DBNAME;encrypt=fasle;user=xxxxxxxxx;password=xxxxxxxx;instance=SQLEXPRESS;";17String username ="xxxxxx";18String password ="xxxxxxxxxx";19conn = DriverManager.getConnection(connString,username,password);20Log.w("Connection","open");21Statement stmt = conn.createStatement();22ResultSet reset = stmt.executeQuery("select * from TableName");2324//Print the data to the console25while(reset.next()){26Log.w("Data:",reset.getString(3));27// Log.w("Data",reset.getString(2));28}29conn.close();3031}catch(Exception e)32{33Log.w("Error connection",""+ e.getMessage());34}35}