Search code examples
androidsql-serverjdbcjtds

Android and MS Sql Conncetion


I am getting an error to connect with MS Sql. Could you please help me find the error, this is my code:

 @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.");

I get this warning, then the execution is stopped.

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

Solution

  • At last I got a Result

    First need to drag and drop the jtds-1.2.5.jar in libs folder

    its avoid the connection error from JDBC

    After Give a connection string like String connString = "jdbc:jtds:sqlserver://IPaddress:1433;databaseName=DB;user=XXXX;password=XXXX;";

    After you need to open a SQL Server manager to enable all TCP Port and pass the port no as 1433

    Atlast declare

    in AndroidManifest.xml