有没有人在android中尝试过JDBC连接,因为在Android 2.3中支持JDBC。
我不得不在没有网络服务的情况下连接Mysql。
我已经申请了,但它给了我错误
public class MysqlConnect extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root"; 
String password = "root";
try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  System.out.println("Connected to the database");
  conn.close();
  System.out.println("Disconnected from database");
} catch (Exception e) {
  e.printStackTrace();
}
}
}我在getConnection中遇到错误。错误类似于java.lang.VerifyError : com.mysql.jdbc.MysqlIO
提前谢谢。
发布于 2018-06-23 16:23:56
我也遇到了同样的错误。
只需将此行添加到gradle依赖项即可解决该错误。
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.44'您可以根据需要更改版本。
添加这个之后,gradle sync将处理所有的事情,你只需要像在简单的java jdbc程序中一样连接到DB即可。我已经使用android studio开发了我的应用程序。
https://stackoverflow.com/questions/4447692
复制相似问题