我在将值从java插入到mysql时遇到了问题,它仍然让我对如何插入自动增量感到困惑--有些人说,如果不插入值,它将是自动的。此外,我还尝试使用add set Int(1,null)和错误。
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); }
发布于 2018-05-05 18:09:08
从命令中排除UserActivityID,DB管理器将为您插入它。
String SQLTIME="INSERT INTO history (UserTimeActivity, UserActivity) VALUES (?,?)";
https://stackoverflow.com/questions/50192510
复制相似问题