1、添加maven依赖
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
2、单处理:更新、删除、插入
public int singleOperate(String sql, Map<Integer, String> map) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection(sql_host, sql_user, sql_password);
PreparedStatement ps = conn.prepareStatement(sql);
for (Map.Entry<Integer, String> entry : map.entrySet()) {
ps.setString(entry.getKey(), entry.getValue());
}
int i = ps.executeUpdate();
ps.close();
conn.close();