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

11,840

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

<manifest>
    .....
    <uses-permission android:name="android.permission.INTERNET" />
    .....
</manifest>
Share:
11,840
ugurrrrr
Author by

ugurrrrr

Updated on June 05, 2022

Comments

  • ugurrrrr
    ugurrrrr almost 2 years

    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

    • I checked connection string.
    • I closed firewall for 1433.
    • I tried configured Sql Server tcp and remote access settings

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

    My environment:

    • Sql Server 2008 R2
    • Eclipse
    • jtds

    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();
    }
    
  • ugurrrrr
    ugurrrrr over 12 years
    Thank you i did this but now i get this error: java.sql.SQLException: Network error IOException: /192.168.1.33:1433 Connection refused
  • havexz
    havexz over 12 years
    you getting network error again? Can you put ur sql statement?
  • ugurrrrr
    ugurrrrr over 12 years
    Yes i'm getting network error again. There is a Sql State on the error line. It is : 08S01 Is that what you want?
  • havexz
    havexz over 12 years
    Are you trying to connect over the wifi? If so check that your phone is also on the wifi network. Or it could be firewall issue. so it is no more an android issue.
  • ugurrrrr
    ugurrrrr over 12 years
    Yes, over the wifi. I did these things already. I connect the phone on the network. I closed firewall but i still get the same error. I think the problem is about sql server. I'm missing something about remote access but what. I coudn't find.
  • havexz
    havexz over 12 years
    Are you able to ping the above address from some other machine?
  • ugurrrrr
    ugurrrrr over 12 years
    Yes, i can. I can also connect to sql server from another pc.
  • ugurrrrr
    ugurrrrr over 12 years
    Thank you for your help. I fixed the problem. The problem was about sql server configuration.