我想将 sql server 连接到我的 android 应用程序。我尝试了下面的代码,但出现异常
包 com.facebook.android;
导入java.sql.Connection;
导入 java.sql.DriverManager;
导入java.sql.ResultSet;
导入 java.sql.Statement;
导入 net.sourceforge.jtds.jdbc.*;
导入android.util.Log;
公共类 ConnectSQL {
公共无效测试SQL(){
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