Connecting android app to Microsoft SQL server 2008

后端 未结 2 1224
挽巷
挽巷 2021-02-03 16:09

First of all. I am new to android application development environment and I am trying to connect to mssqlserver 2008 with simple android application using jtds-1.3.1.jar driver

相关标签:
2条回答
  • 2021-02-03 17:00

    add these code

    StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    
    0 讨论(0)
  • 2021-02-03 17:10

    Try This

    public List<String> dbConnect(String Host, String Port, String db_userid,
                    String db_password) {
                List<String> Db_list = new ArrayList<String>();
                try {
                    String ConnectionString = "jdbc:jtds:sqlserver://" + Host + ":"
                            + Port;
                    // Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                    Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
                    Connection conn = DriverManager.getConnection(ConnectionString,
                            db_userid, db_password);
                    System.out.println("connected");
                    Statement statement = conn.createStatement();
                    String queryString = "select name from sys.databases";
                    ResultSet rs = statement.executeQuery(queryString);
                    while (rs.next()) {
                        Db_list.add(rs.getString(1));
                    }
                } catch (Exception e) {
                    Db_list.add("Error");
                    e.printStackTrace();
                }
                return Db_list;
            }
    

    Refer Sql Database connect Using the JDBC Driver with android

    0 讨论(0)
提交回复
热议问题