我正在尝试从oracle数据库的SQL Insert preparedstatement中获取自动生成的密钥。我试过模仿我能找到的每个例子,并且总是从.executeUpdate()调用中得到一个SQLException。我确信这在prepareStatement()调用中没有第二个参数的情况下工作正常,所以它不是SQL本身。请问我做错了什么?
我收到错误:
I seem to be getting this: [1/19/15 0:50:50:462 EST] 00000054
ConnectionEve A J2CA0056I: The Connection Manager received a fatal
connection error from the Resource Adapter for resource[extracted]. The
exception which was received is
com.ibm.websphere.ce.cm.StaleConnectionException: Protocol
violation:java.sql.SQLException: Protocol violation
代码就像这样
Connection conSOX = AggIOTraceUtil.getJNDISOXConnection(JNDIConn);
PreparedStatement preparedStatement = null;
String sii_agg_id = null;
if (conSOX != null)
{
preparedStatement = conSOX.prepareStatement(SII_SOX_APP_QUERY, new String[] { "SII_TASK_AGG_STATUS_ID" });
preparedStatement.setObject(1, traceObject.getTaskName());
preparedStatement.setObject(2, traceObject.getTaskType());
preparedStatement.setObject(3, traceObject.getSpTaskStartedDate());
ETC等......
preparedStatement.executeUpdate();
// Get the auto generated aggregation ID
ResultSet generatedKeys = preparedStatement.getGeneratedKeys();
if (null != generatedKeys && generatedKeys.next()) {
log.error("Hello");
sii_agg_id = generatedKeys.getString(1);
log.error("SII AGG ID = " + sii_agg_id);
我的SQL查询是:
private static final String SII_SOX_APP_QUERY = "insert into
SII_TASK_AGG_STATUS(SII_TASK_AGG_STATUS_ID, DATA_AGG_TASK_NAME,
"+ "TASK_TYPE, TASK_STARTED_DATE, TASK_COMPLETED_DATE, TASK_LAUNCHED_DATE,
APP_SCANNED, "+ "EXTRA_ENTITLEMENT_CHANGES, IDENTITIES_UPDATED,
LINKS_OR_GROUPS_DELETED, GROUPS_UPDATED, " + "IDENTITIES_CREATED,
GROUPS_CREATED, TASK_MESSAGE, COLUMN_NAMES, DELIMITER, LINE_SKIPPED,
"+ "LOGICAL_APP_NAME, IS_PRIMARY_TIER, AGG_STATUS, DATA_AGG_AUDIT_ID,
SII_TASK_STATUS_ID" + ")
values(SII_TASK_AGG_STATUS_SEQ.NEXTVAL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
?,?,?,?,?,?)";