是否有人在Android中尝试过JDBC连接,因为在Android 2.3中支持JDBC.
我必须在没有Web服务的情况下连接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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在getConnection中遇到错误.错误就像java.lang.VerifyError:com.mysql.jdbc.MysqlIO
提前致谢.
发生这种情况VerifyError
的原因可能是错误的类文件签名。
检查这里:
以前的版本中也包含 JDBC - 关键问题是包含适合您的数据库的驱动程序类并确保它可以与 Android 运行时一起使用。
归档时间: |
|
查看次数: |
28882 次 |
最近记录: |