我用普通JDBC一個DAO層編程,因爲我只有61.38 MB上Java內存我的Tomcat(服務主機)。我有一個MySQL表中有AUTO_INCREMENT
列。目前的實施沒有問題。但我想知道在AUTO_INCREMENT
列中生成的值。返回生成的MySql鍵與JDBC的PreparedStatement
當前代碼在插入新行的方法中顯示如下。
public Integer store(MyBean bean) throws DAOException {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = getConnection();
ps = conn.prepareStatement("INSERT ...");
if (bean.getSomeProperty() != null) {
ps.setShort(1, bean.getSomeProperty());
} else {
ps.setNull(1, Types.SMALLINT);
}
/* Other fields */
int rows = ps.executeUpdate();
if (rows == 1) {
// RETURN the generated value
}
return null;
} catch (SQLException e) {
throw new DAOException(e);
} finally {
...
}
}
我所看到的,這是可能的Hibernate
,而是因爲我有較少的內存,是不是一種可行的選擇。
我很感激幫助。