简体   繁体   中英

Android: Cant connect with database on Remote Server

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM