【发布时间】:2019-07-04 10:05:11
【问题描述】:
我目前正在尝试建立从我的 Android 应用到在我的树莓派上运行的 MySQL 服务器的连接。
我通过将库添加到模块菜单中的依赖项中,正确地将库添加到了 android studio。
我在我的程序中实现了这样的 JDBC 方法。
public void readDatabase(String query)throws Exception{
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101/mydb","user","mypassword");
statement = connection.createStatement();
resultSet = statement.executeQuery(query);
System.out.println(resultSet);
}catch (ClassNotFoundException e){
e.printStackTrace();
}finally {
close();
}
}
private void close(){
try {
if (resultSet != null){
resultSet.close();
}
if (statement != null){
statement.close();
}
if ( connection != null){
connection.close();
}
}catch (Exception e){
}
}
每次我启动程序时,我都会收到一个找不到类的错误。 它说:
W/System:ClassLoader 引用未知路径:system/framework/mediatek-cta.jar I/System.out: e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
我尝试以不同的方式搜索问题,但我无法找出问题所在。
我什至不知道 cta 类是什么。也许有人可以在这里帮助我。
【问题讨论】:
-
有什么安全的方法可以解决这个问题吗?
标签: android mysql android-studio jdbc