eclipse 如何从我的 android 应用程序连接到 sql server?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8548700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i connect to sql server from my android application?
提问by ugurrrrr
I'm developing an android application. I need connect to sql server. I wrote a code for test connection but i get this error :
我正在开发一个 android 应用程序。我需要连接到 sql server。我为测试连接编写了代码,但出现此错误:
java.sql.SQLException: Network error IOException: Permission denied
java.sql.SQLException: 网络错误 IOException: 权限被拒绝
- I checked connection string.
- I closed firewall for 1433.
- I tried configured Sql Server tcp and remote access settings
- 我检查了连接字符串。
- 我关闭了 1433 的防火墙。
- 我尝试配置 Sql Server tcp 和远程访问设置
but i still get the same error. What is my mistake?
但我仍然遇到同样的错误。我的错误是什么?
My environment:
我的环境:
- Sql Server 2008 R2
- Eclipse
- jtds
- Sql Server 2008 R2
- 蚀
- 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();
}
采纳答案by havexz
You have to add the following permission to your application manifest file.
您必须向应用程序清单文件添加以下权限。
<manifest>
.....
<uses-permission android:name="android.permission.INTERNET" />
.....
</manifest>

