mysql invalid driver_mysql踩坑

com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '******' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

解决方法:

jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8

换成:

jdbc:mysql://localhost:3306/mybatis?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true

jdbc:mysql://localhost:3306/mybatis?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true

centos报错:Access denied for user 'root'@'localhost' (using password: YES)

也有可能只是密码输入错误了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个使用Java和MySQL实现的学生成绩信息管理系统代码示例: 首先,需要在MySQL中创建一个名为“students”的数据库,并创建一个名为“student_scores”的数据表,其中包含“name”(姓名)、“id”(学生ID)和“marks”(成绩)三个字段。 然后,需要在Java中使用JDBC连接到MySQL数据库,并编写相应的Java代码实现学生成绩信息的添加、查看、搜索和删除功能。 具体代码如下: ``` import java.sql.*; public class StudentScoreManagementSystem { private static final String DB_URL = "jdbc:mysql://localhost:3306/students"; private static final String USER = "root"; private static final String PASS = "password"; public static void main(String[] args) { Connection conn = null; Statement stmt = null; try { Class.forName("com.mysql.jdbc.Driver"); System.out.println("Connecting to database..."); conn = DriverManager.getConnection(DB_URL, USER, PASS); System.out.println("Creating statement..."); stmt = conn.createStatement(); int choice; do { System.out.println("\n1. Add student\n"); System.out.println("2. View all students\n"); System.out.println("3. Search for a student\n"); System.out.println("4. Delete a student\n"); System.out.println("5. Exit\n"); System.out.println("Enter your choice: "); choice = Integer.parseInt(System.console().readLine()); switch (choice) { case 1: System.out.println("Enter student name: "); String name = System.console().readLine(); System.out.println("Enter student ID: "); int id = Integer.parseInt(System.console().readLine()); System.out.println("Enter student marks: "); int marks = Integer.parseInt(System.console().readLine()); String sql = "INSERT INTO student_scores (name, id, marks) VALUES ('" + name + "', " + id + ", " + marks + ")"; stmt.executeUpdate(sql); System.out.println("Student added successfully!"); break; case 2: sql = "SELECT * FROM student_scores"; ResultSet rs = stmt.executeQuery(sql); System.out.println("Name\tID\tMarks"); while (rs.next()) { String studentName = rs.getString("name"); int studentID = rs.getInt("id"); int studentMarks = rs.getInt("marks"); System.out.println(studentName + "\t" + studentID + "\t" + studentMarks); } rs.close(); break; case 3: System.out.println("Enter student name to search for: "); String searchName = System.console().readLine(); sql = "SELECT * FROM student_scores WHERE name='" + searchName + "'"; rs = stmt.executeQuery(sql); if (rs.next()) { int studentID = rs.getInt("id"); int studentMarks = rs.getInt("marks"); System.out.println("Name\tID\tMarks"); System.out.println(searchName + "\t" + studentID + "\t" + studentMarks); } else { System.out.println("Student not found!"); } rs.close(); break; case 4: System.out.println("Enter student ID to delete: "); int deleteID = Integer.parseInt(System.console().readLine()); sql = "DELETE FROM student_scores WHERE id=" + deleteID; int rowsDeleted = stmt.executeUpdate(sql); if (rowsDeleted > 0) { System.out.println("Student deleted successfully!"); } else { System.out.println("Student not found!"); } break; case 5: System.out.println("Exiting program... Goodbye!"); break; default: System.out.println("Invalid choice!"); } } while (choice != 5); } catch (SQLException se) { se.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); } catch (SQLException se2) {} try { if (conn != null) conn.close(); } catch (SQLException se) { se.printStackTrace(); } } } } ``` 该程序使用JDBC连接到MySQL数据库,并提供了以下功能: 1. 添加学生。 2. 查看所有学生。 3. 搜索学生。 4. 删除学生。 5. 退出程序。 通过以上Java和MySQL代码示例,您可以自行修改并完善学生成绩信息管理系统。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值