long id1 = 3;
long id2 = 3;
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager
.getConnection("jdbc:mysql://localhost/test?user=root&password=root");
String sql = "insert ignore into person (id1,id2,date) values (?,?,?)";
java.sql.PreparedStatement ps = conn.prepareStatement(sql);
ps.setLong(1, id1);
ps.setLong(2, id2);
ps.setDate(3, new Date(Date.parse(new java.util.Date().toString())));
int c = ps.executeUpdate();
System.out.println(c);
ps.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
person表添加索引(栏位添加除主键外),索引类型unique,索引方式btree