gpt4 book ai didi

java - Android连接Mysql数据库

转载 作者:行者123 更新时间:2023-11-29 17:19:54 24 4
gpt4 key购买 nike

我无法在 Android 应用程序中连接到远程 mysql 数据库,因为该应用程序找不到合适的驱动程序。

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
applicationId "com.example.test.testapp"
minSdkVersion 20
targetSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//https://stackoverflow.com/questions/37048731/gson-library-in-android-studio/37049457
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.android.support:design:26.1.0'
// implementation 'org.mariadb.jdbc:mariadb-java-client:2.1.2'
compile 'com.android.support:support-annotations:27.1.1'
// implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// implementation files('libs/mysql-connector-java-5.1.46.jar')
// compile project(':mysql-connector-java-5.1.46')
// compile project(':libs/mysql-connector-java-5.1.46.jar')
implementation files('libs/mysql-connector-java-5.1.46-bin.jar')
}

这是我的java类,发生异常。

public ServerSave() throws SQLException, ClassNotFoundException {
// load and register JDBC driver for MySQL
Class.forName("com.mysql.jdbc.Driver");

this.conn = getConnection("jdbc:mariadb://remote.host.example/" + SQL_DATABASE, SQL_USER_NAME, SQL_PASSWORD);
}

我认为这是一个配置问题,但我不知道如何解决。我将 mysql jar 文件复制到我的 android 项目文件夹中的 libs 目录中。我在这个项目中使用 android studio。

感谢您的帮助。

最佳答案

我没有直接解决它。我创建了一个与 mysql 数据库对话的rest api。

关于java - Android连接Mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51311820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com