我正在尝试在我的Android应用程序中使用JDBC连接到远程数据库来执行插入,查询等.我已成功连接并在不同的JAVA项目中完成这些操作.所以我认为既然Android是Java,我可以直接移植相关代码,为驱动程序添加相同的构建路径等.但它给了我错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)
我真的不认为这是一个代码问题,因为相同的代码在Java项目中工作(我只是在main()中执行).但在此参考它是:
String url = "jdbc:mysql://localhost:3306/eventhub_test"; //
String user = "root";
String pass = "";
SQLUtils sqlu = new SQLUtils(url, user, pass);
Run Code Online (Sandbox Code Playgroud)
//我做的SQLUtils类:
public class SQLUtils {
private String CONNECTION_URL;
private String user;
private String pass;
private java.sql.Statement stmt;
private java.sql.Connection conn;
public SQLUtils(String conn_url, String user, String pass) {
this.CONNECTION_URL = conn_url;
this.user = user;
this.pass = pass;
}
public void init() throws IllegalAccessException, InstantiationException, ClassNotFoundException, SQLException {
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection(CONNECTION_URL, user, pass);
stmt …Run Code Online (Sandbox Code Playgroud) 我是android开发的初学者.现在我试图通过emulator.MS SQL 2008 R2在另一台(服务器)机器上运行来连接MS SQL 2008 R2.我收到以下错误:
The TCP/IP connection to the host xxx.xxx.xx.x\SQL2008R2DEV has failed;
error: null;
verify connection properties.
make sure that instance of SQL server running on the host and accepting TCP/IP connection to the port are not blocked by Windows Firewall.
Run Code Online (Sandbox Code Playgroud)
注意我在java应用程序中完成了这个.我也可以访问我的数据库.但为什么不能在android程序中?有什么想法吗?
注意:两台服务器和我的PC都通过LAN连接.