1

I'm new to android. When I try to connect my android app to MS SQL Server database using eclipse android emulator, the LogCat showed me the exception "Error Connection - NULL". I've searched many posts over the internet related to this issue but yet to get a solution for that.

Here is my code which try to connect to database after i click a button. I have copy jtds-1.2.7.jar into the libs folder. Also, set the permission to INTERNET in my manifest file. Can anyone let me know what's wrong with that? Please ~~

    public void onClick1(View view) {
        Log.i("Android"," MySQL Connect Example.");
        Connection conn = null;
        try {
            String driver = "net.sourceforge.jtds.jdbc.Driver";
            Class.forName(driver).newInstance();
            String connString = "jdbc:jtds:sqlserver://serverIP:1435/db_name;encrypt=fasle;user=xxxxxx;password=!xxxxxx;instance=SQLEXPRESS;";
            String username = "xxxxxx";
            String password = "!xxxxxx";
            conn = DriverManager.getConnection(connString,username,password);
            Log.w("Connection","open");
            Statement stmt = conn.createStatement();
            ResultSet reset = stmt.executeQuery("select * from xxxxxx");
            //Print the data to the console
            while(reset.next()){
                Log.w("Data:",reset.getString(3));
            }
            conn.close();
            } catch (Exception e)
            {
                Log.w("Error connection","" + e.getMessage());
            }   
    }   

LogCat - After throw a lot of garbage, showing Error Connection, NULL

willyip237
  • 19
  • 1
  • 6

0 Answers0