Java 用户活动ID自动增量
我在从java向mysql中插入值时遇到了问题,它仍然让我对如何插入自动增量感到困惑。有人说,它将自动插入值而不插入值。此外,我还尝试使用addsetint(1,null)并在那里出错Java 用户活动ID自动增量,java,Java,我在从java向mysql中插入值时遇到了问题,它仍然让我对如何插入自动增量感到困惑。有人说,它将自动插入值而不插入值。此外,我还尝试使用addsetint(1,null)并在那里出错 public void mase(){ String time=dateFormat.format(date); String SQLTIME="INSERT INTO history (UserActivityID, UserTimeActivity, UserActivity) VALUES
public void mase(){
String time=dateFormat.format(date);
String SQLTIME="INSERT INTO history (UserActivityID, UserTimeActivity, UserActivity) VALUES (null,?,?)";
try {
JOptionPane.showMessageDialog(this, "?");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/atm?zeroDateTimeBehavior=convertToNull", "root", "");
PreparedStatement prstm=con.prepareStatement(SQLTIME);
prstm = con.prepareStatement(SQLTIME,PreparedStatement.RETURN_GENERATED_KEYS);
prstm.setString(1, time);
prstm.setString(2,"Cash Withdraw");
int rowsInserted = prstm.executeUpdate();
if (rowsInserted > 0) {
JOptionPane.showMessageDialog(this," inserted successfully!");
}
} catch (SQLException | HeadlessException | ClassCastException ex) {
JOptionPane.showMessageDialog(this, ex);
}
JOptionPane.showMessageDialog(this, time);
}从命令中排除
用户活动ID
,DB管理器将为您插入该ID
String SQLTIME=“插入历史记录(UserTimeActivity,UserActivity)值(?,)”