我正在尝试将我的Android应用程序与本地MySQL数据库连接,然后使用JDBC获取数据库的一些内容。所以我尝试了这段代码来连接到数据库:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/rpg","root", "whatever");
Statement statement = connection.createStatement();
final ResultSet resultSet = statement.executeQuery("select * from player");
Log.i("Content",resultSet.getString(0));
}catch (Exception e) {
e.printStackTrace();
}
我在清单中给予了互联网许可 (<uses-permission android:name="android.permission.INTERNET"/>
(
并将mySQL连接器实现为库(mysql-connector-java-8.0.12.jar(。
当我想启动它时,出现此错误:
Default interface methods are only supported starting with Android N (--min-api 24): void com.mysql.cj.protocol.AuthenticationPlugin.destroy()
Default interface methods are only supported starting with Android N (--min-api 24): void com.mysql.cj.protocol.MessageSender.send(com.mysql.cj.protocol.Message)
Default interface methods are only supported starting with Android N (--min-api 24): byte com.mysql.cj.protocol.MessageReader.getMessageSequence()
Default interface methods are only supported starting with Android N (--min-api 24): com.mysql.cj.result.Row com.mysql.cj.result.RowList.get(int)
Default interface methods are only supported starting with Android N (--min-api 24): com.mysql.cj.protocol.Message com.mysql.cj.interceptors.QueryInterceptor.postProcess(com.mysql.cj.protocol.Message, com.mysql.cj.protocol.Message)
null
com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:UsersAlexanderDesktopProgrammierungTesting2applibsmysql-connector-java-8.0.12.jar
com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
com.android.tools.r8.CompilationFailedException: Compilation failed to complete
com.android.tools.r8.utils.AbortException
这听起来像我必须将 minSdkVersion 增加到 24 对吧?所以我这样做了,然后出现了这个错误:
Invoke-customs are only supported starting with Android O (--min-api 26)
null
com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:UsersAlexanderDesktopProgrammierungTesting2applibsmysql-connector-java-8.0.12.jar
com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
com.android.tools.r8.CompilationFailedException: Compilation failed to complete
com.android.tools.r8.utils.AbortException
所以我也把它增加到 26,然后得到这个错误:
Installation failed with message INSTALL_FAILED_OLDER_SDK: Failed parse during installPackageLI: /data/app/vmdl127069021.tmp/base.apk (at Binary XML file line #7): Requires newer sdk version #26 (current version is #25).
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.
WARNING: Uninstalling will remove the application data!
Do you want to uninstall the existing application?
但无论如何,感觉我完全错了。有人知道我该怎么做。
在
- 项目窗口中打开
build.gradle
(模块:应用程序( - 将
minSdkVersion
更改为 24 或更高