这是我的连接类,我有注释失败的地方,以及捕获异常的地方。
import android.annotation.SuppressLint;
import android.os.StrictMode;
import android.util.Log;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectionClass {
String ip = "cis-linux2.temple.edu";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "*********";
String un = "******";
String password = "*******";
@SuppressLint("NewApi")
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName(classs); //throw exception here
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {//exception thrown
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
}
我添加了lib jtds-1.2.7.jar,这是我在这里需要的http://www.parallelcodes.com/connect-android-to-ms-sql-database-2/
转到新模块,然后导入.jar,我可以在Android Studio边栏上看到与我的应用程序和Gradle Scripts文件夹相同的级别,但它仍然无效。是否有另一种方法来导入我应该使用的库,或者它是自己的代码吗?