俩个jar包重叠
老师我得mysql版本和包好像都不对应,但是两个包一起用就好了,怎么回事,但是查询不管用哪个包都能输出,修改就得俩个包都装进去后运行数据表得值才变化,每次去掉一个包运行java时提示有错误是否继续运行,但代码没有显示错误。






package com.imooc.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCDemo01 {
public static void main(String[] args) throws ClassNotFoundException {
Connection conn = null;
Statement stat = null;
ResultSet res = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test"
+ "?useSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8",
"root", "123456");
stat = conn.createStatement();
String sql = "select * from users";
String sql1 = "update user set username='qqq',password='1389' where totlogin = 2";
int i = stat.executeUpdate(sql1);
if (i > 0) {
System.out.println("保存成功!");
}
res = stat.executeQuery(sql);
while (res.next()) {
int state = res.getInt("state");
String username = res.getString("username");
String password = res.getString("password");
System.out.println(state + username + password);
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} finally {
if (stat != null) {
try {
stat.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
stat = null;
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
conn = null;
}
if (res != null) {
try {
res.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
res = null;
}
}
}
}0
收起
正在回答
5回答
同学你好,在程序中已经完成加载驱动,建立数据库连接的操作了~

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
3. Java 数据库开发与实战应用
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程







恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星