ugurrrrr
ugurrrrr

Reputation: 51

How can i connect to sql server from my android application?

I'm developing an android application. I need connect to sql server. I wrote a code for test connection but i get this error :

java.sql.SQLException: Network error IOException: Permission denied

but i still get the same error. What is my mistake?

My environment:

My Code is:

try
{  
  Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
  **Connection conn=DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.1.33:1433/Android_Deneme;instance=CASPER\\MORTY;user=ugur;password=1234");**
  String sql="insert into tablo1(ad,yas) values(?,?)";
  PreparedStatement prepared = conn.prepareStatement(sql);
  prepared.setString(1, "ali");
  prepared.setInt(2, 30);
  prepared.executeUpdate();
}
catch(Exception e)
{
  e.printStackTrace();
}

Upvotes: 3

Views: 12006

Answers (1)

havexz
havexz

Reputation: 9590

You have to add the following permission to your application manifest file.

<manifest>
    .....
    <uses-permission android:name="android.permission.INTERNET" />
    .....
</manifest>

Upvotes: 1

Related Questions