需求:MYSQL主键存在则更新,不存在则插入
package com.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
/***
* 需求:MYSQL主键存在则更新,不存在则插入
*
* 解决:
* 1、主键为:PRIMARY KEY (dbName, tableName, TIMES) ,
* 2、MYSQL主键存在则更新,不存在则插入的解决方案(ON DUPLICATE KEY UPDATE)
*/
public class MysqlTest {
public static void main(String[] args) {
try {
//mysql的配置
Connection connection = null;
PreparedStatement preparedStatement;
String username = "root";
String password = "123456";
String drivername = "com.mysql.jdbc.Driver";
String dbur