1 回答
TA贡献1895条经验 获得超7个赞
经过一番挖掘,我找到了第二个问题的解决方案。让我知道我是否会改进它。
int lastId() {
int newSheetNumber=0;
String query = "SELECT MAX(ID) FROM SHEETSDB WHERE MONTH(`SHEETDATE`)=MONTH(NOW()) AND YEAR(`SHEETDATE`)=YEAR(NOW())";
try {
preparedStatement = conn.prepareStatement(query);
rs = preparedStatement.executeQuery();
if (!rs.next()) {
newSheetNumber = 1;
}else {
newSheetNumber = rs.getInt(1) + 1;
}
preparedStatement.close();
rs.close();
//System.out.println("The new sheet is: " + newSheetNumber);
} catch (SQLException ex) {
System.err.println("Error " + ex);
}
return newSheetNumber;
}
添加回答
举报