0
我要到SQL Server連接到我的Android app.i嘗試下面的代碼,但得到的異常連接SQL服務器通過jdts
包com.facebook.android的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;
公共類ConnectSQL {
公共無效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
對我也有同樣的錯誤。我已經使用1.2.5.jar文件作爲庫文件,並嘗試使用1.2.7和1.3.0版本,但沒有成功... –