基于JDBC的。 public class JDBCDemo { public static void main(String[] args) throws SQLException { // System.out.println(get(1)); System.out.println(insert(new Test(null, 66, "jdbc insert"))); } public static int insert(Test test) throws SQLException { Connection connection = null; PreparedStatement preparedStatement = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/gp?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "root", "123456");