问题描述
我试图学习如何使用JDBC将应用程序连接到mysql数据库。
我正在使用Android Studio。
我下载了来自de mysql网站的mysql-connector-java-5.1.37。
只需将mysql-connector-java-5.1.37-bin.jar放在Hello World应用程序的libs文件夹中并编译即可:
Im trying to learn how to use the JDBC to connect a application to a mysql database.
Im using the Android Studio.
I downloaded "mysql-connector-java-5.1.37" from de mysql website.
Just for put the "mysql-connector-java-5.1.37-bin.jar" in libs folder of a Hello World application and compile i recive :
build.gradle:
the build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "br.com.myaplication.helloworld"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
}
请帮帮我:) thnx
please, help me :) thnx
推荐答案
因为分布式mysql-connector- java-5.1.37-bin.jar是为Java1.8编译的,当前的Android dex编译器无法识别它。
Because Distributed mysql-connector-java-5.1.37-bin.jar is compiled for Java1.8, current Android dex compiler cannot recognize it.
$ javap -v com/mysql/jdbc/JDBC42Helper.class| grep "major version"
major version: 52
另一方面,mysql-connector -java-5.1。 36 .jar是为Java1.6编译的。
On the oher hand, mysql-connector-java-5.1.36.jar is compiled for Java1.6.
$ javap -v com/mysql/jdbc/JDBC4Connection.class |grep "major version"
major version: 50
,因此需要Java1.8。
5.1.37 supports JDBC4.2, so requires Java1.8.
这篇关于android JDBC mysql java连接器app:preDexDebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!