no suitable driver Sql server jtds

為{幸葍}努か 提交于 2019-12-12 03:24:16

问题


what ever I did I get the same error NO SUITABLE DRIVER I have sql server 2014 and I am using Eclipse mars I tried every jtds i found no solution I am new on android and java, i really need help.

ListView lv = null;
Connection connx = null;
SimpleAdapter sa = null;
String sqlreq = "select * from news";
@SuppressLint("NewApi")
private Connection cnx() //connection to sqlserver
{
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
    StrictMode.setThreadPolicy(policy);
    Connection conn = null;
    String ConnUrl = null;



    try 
    {
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        ConnUrl = "jdbc:jdts:sqlserver://xxxxxx:1433;DatabaseName=xxxx;ssl=require";
        conn=DriverManager.getConnection(ConnUrl);

    } catch (SQLException e) 
    {
        Log.e("Error", e.getMessage());
    }
    catch (ClassNotFoundException e) 
    {
        Log.e("Error", e.getMessage());
    }
    catch (Exception e) 
    {
        Log.e("Error", e.getMessage());
    }
    return conn;
}



public void SqlQuery(String SqlCmnd) 
{
    connx = cnx();
    ResultSet rs;
    try 
    {
        Statement stm = connx.createStatement();
        rs = stm.executeQuery(SqlCmnd);
        List<Map<String, String>> data = null;
        data = new ArrayList<Map<String, String>>();

        while (rs.next()) {

            Map<String, String> datanum = new HashMap<String, String>();
            datanum.put("A", rs.getString("title"));
            datanum.put("B", rs.getString("idnews"));
            data.add(datanum);
        }
        String[] from = {"A","B"};
        int [] views ={R.id.Titleid,R.id.Articleid};
        sa = new SimpleAdapter(this, data, R.layout.model, from, views);
        lv.setAdapter(sa);
    } 
    catch (Exception e) {
        Log.e("Error", e.getMessage());
    }

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    lv = (ListView)findViewById(R.id.listView1);
    setContentView(R.layout.activity_main);
    SqlQuery(sqlreq);
}

来源:https://stackoverflow.com/questions/36560421/no-suitable-driver-sql-server-jtds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!