Menu

Can use jTDS for my phone?

2017-01-05
2017-01-05
  • Loren Natasya Gunawan

    I try some tutorial for connect Android Studio 2.2.3 and MS SQL server 2012:
    this is my source code:

    import android.annotation.SuppressLint;
    import android.os.StrictMode;
    import android.util.Log;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;

    /*
    * Created by loren10 on 27/12/2016.
    /

    public class DbHelper {
    String ip = "";
    String classs = "net.sourceforge.jtds.jdbc.Driver";
    String db = "";
    String un = "";
    String password = "";

    @SuppressLint("NewApi")
    public Connection CONN() {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        Connection conn = null;
        String ConnURL = null;
        try {
    
            Class.forName(classs).newInstance();
            ConnURL = "jdbc:jtds:sqlserver://" + ip + "/" + db + ";user=" + un + ";password=" + password + ";";
            conn = DriverManager.getConnection(ConnURL);
        } catch (SQLException se) {
            Log.e("ERROR1", se.getMessage());
        } catch (ClassNotFoundException e) {
            Log.e("ERROR2", e.getMessage());
        } catch (Exception e) {
            Log.e("ERROR3", e.getMessage());
        }
        return conn;
    }
    

    }

    after i build in my phone this is my problem : "E/ERROR: net.sourceforge.jtds.jdbc.Driver".. can anyone help me for solve this problem please?

     
  • Bernd Eckenfels

    Bernd Eckenfels - 2017-01-05

    Can you tell us which of the 3 ERRORx cases your error is? You should also use e.toString() instead of getMessage() to make the logs more helpful. I have no experiemce with Android so I dont know if it can work, but it does look like the driver JAR is not found or loaded.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.