Tomcat(サービスホスティング)のJavaメモリには61.38 MBしかないため 、プレーンJDBCでDAOレイヤーをプログラミングしています。MySQLに列を持つテーブルがあります。現在の実装には問題はありません。しかし、私は列で生成された値を知りたいです。AUTO_INCREMENT
AUTO_INCREMENT
新しい行を挿入するメソッドでは、現在のコードは次のようになります。
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
たが、メモリが少ないため、実行可能なオプションではありません。
私は助けに感謝します。