sdk版本:Android 12
使用mysql-connector-java-8016.jar
服务器mysql版本mysql8012
public class DbOpenHelper {
private static final String driver = "com.mysql.cj.jdbc.Driver";
private static final String url = "jdbc:mysql://xxx.xxx.xxx.xxx:3306/wsgd?useSSL=false&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&serverTimezone=UTC";
private static final String user = "root";
private static final String pwd = "2#w1*s>2g]d0/";
public static Connection conn;
public static Statement sql = null;
public static ResultSet rs = null;
/**
* mysql连接
*
* @return
*/
public static Connection getConnection() {
if (conn == null) {
try {
//获取 mysql 驱动
Class.forName(driver);
//获取连接
conn = (Connection) DriverManager.getConnection(url, user, pwd);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
return conn;
}
}
报错:java.lang.NoClassDefFoundError: Failed resolution of: Ljava/sql/SQLType;
报错:Caused by: java.lang.ClassNotFoundException: Didn't find class "java.sql.SQLType" on path: DexPathList[[dex file "/data/data/com.example.wsgd/code_cache/.overlay/base.apk/classes4.dex", dex file "/data/data/com.example.wsgd/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/JKmtUgUAorwJxqxzPI9Yjg==/com.example.wsgd-9hZSrcfb2A5vmuM8li-9UQ==/base.apk"],nativeLibraryDirectories=[/data/app/JKmtUgUAorwJxqxzPI9Yjg==/com.example.wsgd-9hZSrcfb2A5vmuM8li-9UQ==/lib/x86_64, /system/lib64, /system_ext/lib64]]
感觉想sql连接串问题 可是看了很多方案都无法解决
JDK是什么版本的,没有写SQL语句的配置吗?参考一下有没有不一样的。
jdbc:mysql://localhost:3306/citymanager?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
驱动包版本高了,降低一点。
你确定mysql数据库版本是8么。
换几个msql驱动包试下