我想将sql server连接到我的android app.i尝试下面的代码,但得到异常
包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()); }
} }
我收到此异常
连接错误(1833):net.sourceforge.jtds.jdbc.Driver
答案 0 :(得分:0)
右键点击您的项目==? properties ==>订单和出口==>检查jtds
并清理你的项目并重建你的apk
我认为它会起作用。