0

i want to connect sql server to my android app.i tried below code but getting exception

package com.facebook.android;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import net.sourceforge.jtds.jdbc.*;

import android.util.Log;

public class ConnectSQL {

public void testSQL (){

      Log.d("Android"," MySQL Connect Example.");
      Connection conn = null;
        try {
             String driver = "net.sourceforge.jtds.jdbc.Driver";
             Class.forName(driver);
            //test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
             String connString = "jdbc:jtds:sqlserver://localhost:1433/Test";
            String username = "";
            String password = "";
            conn = DriverManager.getConnection(connString,username,password);
            Log.d("Connection","open");       
            Statement stmt = conn.createStatement();    
            ResultSet reset = stmt.executeQuery("select * from emp");

           //Print the data to the console    
          while(reset.next()){
            Log.d("Data:",reset.getString(1));
           //Log.w("Data",reset.getString(2
            //System.out.println("Result :" + reset.getInt("1")); 
          }
         conn.close();

      } catch (Exception e)       
         { 
             Log.d("Error connection","" +
           e.getMessage());
          }

} }

I am getting this exception

Error connection(1833): net.sourceforge.jtds.jdbc.Driver

1
  • same error to me also .I have used 1.2.5.jar file as library file and also tried with 1.2.7 and 1.3.0 versions but no success... Commented Mar 6, 2013 at 6:05

1 Answer 1

0

Right click on your project ==? properties ==> order and export ==> check the jtds
and clean your project and rebuild your apk.
i think its going to work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.