安卓应用连接数据库应用报错(两天未解决的问题,求大神指导)
错误信息:08-0210:22:55.405:W/System.err(763):java.lang.ClassNotFoundException:com.mysql.j...
错误信息:
08-02 10:22:55.405: W/System.err(763): java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
08-02 10:22:55.410: W/System.err(763): at java.lang.Class.classForName(Native Method)
08-02 10:22:55.410: W/System.err(763): at java.lang.Class.forName(Class.java:217)
08-02 10:22:55.410: W/System.err(763): at java.lang.Class.forName(Class.java:172)
08-02 10:22:55.410: W/System.err(763): at com.example.database.DBAdapter.getConnection(DBAdapter.java:58)
我的DBAdapter类getConnection:
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DATABASE_URL + DATABASE_NAME,
DATABASE_USER, DATABASE_PASSWORD);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
应用结构如下:(能否跟我说下Android 4.4.2, Android Private Libraries, Android Dependencies, libs的区别)
另外,我new的之前一个Java项目连接数据库的测试却能成功。
DBAdapter类没变,项目结构如下:
我想问到底哪里出问题了。谢谢
08-02 10:35:42.760: W/dalvikvm(2175): VFY: unable to resolve static method 16988: Ljava/lang/management/ManagementFactory;.getThreadMXBean ()Ljava/lang/management/ThreadMXBean;
08-02 10:35:42.760: D/dalvikvm(2175): VFY: replacing opcode 0x71 at 0x0079
08-02 10:35:42.820: W/System.err(2175): com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
现在又报这个错误了。 展开
08-02 10:22:55.405: W/System.err(763): java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
08-02 10:22:55.410: W/System.err(763): at java.lang.Class.classForName(Native Method)
08-02 10:22:55.410: W/System.err(763): at java.lang.Class.forName(Class.java:217)
08-02 10:22:55.410: W/System.err(763): at java.lang.Class.forName(Class.java:172)
08-02 10:22:55.410: W/System.err(763): at com.example.database.DBAdapter.getConnection(DBAdapter.java:58)
我的DBAdapter类getConnection:
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DATABASE_URL + DATABASE_NAME,
DATABASE_USER, DATABASE_PASSWORD);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
应用结构如下:(能否跟我说下Android 4.4.2, Android Private Libraries, Android Dependencies, libs的区别)
另外,我new的之前一个Java项目连接数据库的测试却能成功。
DBAdapter类没变,项目结构如下:
我想问到底哪里出问题了。谢谢
08-02 10:35:42.760: W/dalvikvm(2175): VFY: unable to resolve static method 16988: Ljava/lang/management/ManagementFactory;.getThreadMXBean ()Ljava/lang/management/ThreadMXBean;
08-02 10:35:42.760: D/dalvikvm(2175): VFY: replacing opcode 0x71 at 0x0079
08-02 10:35:42.820: W/System.err(2175): com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
现在又报这个错误了。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询