0

Good day, I am creating an Android program that connects to MS SQL 2012 database on a remote server.. Im currently using Eclipse Juno.. my code works on Eclipse Helius but when I transfer my code to Juno, I encounter problems with connecting to database... I already added drivers such as "mysql-connector-java-5.1.33" and "jtds-1.2.5"

Here is my code:

Connection conn = null;
    int a = 0;
    try
    {

        Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
        String connString = "jdbc:jtds:sqlserver://xxx.xxx.xxx.xxx:1433/SAMPLEDB;encrypt=false;user=XX;password=XXXXXXX;instance=SQLEXPRESS;";
        String username = "XX";
        String password = "XXXXXXX";
        String sql = "";

        conn = DriverManager.getConnection(connString, username, password);
        a++;
        Statement stmt = conn.createStatement();
        a++;

        sql = "Select * from NUMBERFILE";
        ResultSet reset = stmt.executeQuery(sql);

        a++;
        while(reset.next())
        {
            tDisplayS.setText(reset.getString("NUMBER").toString());
        }

    }
    catch(Exception e)
    {
        Toast.makeText(getApplicationContext(), e.getMessage() + " " + a, Toast.LENGTH_LONG).show();
    }

I used "a" to indicate where it would stop then it only has a value of 1 so meaning it cant establish connection.. I already searched for similar problems with mine but still no luck..

Please help.. appreciate all your reply..

Thanks!

Katsuhiro
  • 19
  • 2
  • What is the exact exception class name and exception message text? – mjn Nov 10 '14 at 07:36
  • It says "Cannot connect to Server XXX.XXX.XXX.XXX" but in helius it connects successfully... I also try to use jtds 1.3.1 then the error gets NULL .. and still gets the error on .getConnection @mjn – Katsuhiro Nov 10 '14 at 08:22
  • Have you tried to put this in an AsyncTask?? If you have access to the DBServer I would create a Web Service and make my APK smaller without adding the connectors. – Alan Faz Jan 07 '15 at 04:52

1 Answers1

0

this problem occurs because the versions of android 4.x onwards has protection in their trhead to stop the application if the process takes more than 5 seconds

happens to me as well and I'm trying to fix it

nager
  • 1
  • 1