Android和MS Sql Conncetion

时间:2016-04-02 14:36:18

标签: android sql-server jdbc jtds

我收到错误以连接MS Sql。你能帮我找到错误,这是我的代码:

 @SuppressLint("NewApi")
    public void  SqlConnectTest(View view)
    {
        Log.i("Android"," SQL Connect Example.");
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);   
        Connection conn = null;
            try {
            //String driver = "net.sourceforge.jtds.jdbc.Driver";
            //"net.sourceforge.jtds.jdbc.Driver"
            //Class.forName(driver);
            Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
            Log.i("Android"," SQL Class Connect Example.");

我收到此警告,然后执行停止。

04-02 10:33:40.002: W/Error connection(1646): net.sourceforge.jtds.jdbc.Driver

1 个答案:

答案 0 :(得分:0)

最后我得到了一个结果

首先需要将jtds-1.2.5.jar拖放到libs文件夹

避免JDBC的连接错误

给出一个连接字符串之后 String connString =" jdbc:jtds:sqlserver:// IPaddress:1433; databaseName = DB; user = XXXX; password = XXXX;&#34 ;;

需要打开SQL Server管理器以启用所有TCP端口并将端口号传递为1433

Atlast宣布  

AndroidManifest.xml中的