使用Postgresql JDBC时,使用executeUpdate语句插入行但结果为零。我发现插入了数据。 API文档告诉executeUpdate方法返回受影响的行数。
mSqlInsertEventHist = "INSERT INTO " + DatabaseTables.EVENT_HIST +
" ( event_id, mntr_id, mntr_zone, mntr_name, mntr_class_name, mntr_class_sub_type, host_name, ip_addr, " +
" metric_id, metric_name, perf_name, object_name, event_type, event_master_id, " +
" event_name, event_level, event_msg, threshold, event_recv_day, event_reco_dt, event_recv_dt," +
" event_saved_dt, blackout_yn, msg_filter_yn ) " +
" VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " + " now() " + ", ?, ? ) ";
mPstmtInstEvtHist.setLong(1, eventid);
mPstmtInstEvtHist.setInt(2, mntrid);
mPstmtInstEvtHist.setString(3, mntrZone);
mPstmtInstEvtHist.setString(4, mntrname);
mPstmtInstEvtHist.setString(5, mntrClsName);
mPstmtInstEvtHist.setString(6, mntrClsSubType);
mPstmtInstEvtHist.setString(7, hostname);
mPstmtInstEvtHist.setString(8, ipAddr);
mPstmtInstEvtHist.setInt(9, Integer.parseInt((String)dataobj.get(MQConstants.METRIC_ID)));
mPstmtInstEvtHist.setString(10, metricname);
mPstmtInstEvtHist.setString(11, perfname);
mPstmtInstEvtHist.setString(12, objectname);
mPstmtInstEvtHist.setString(13, dataType);
mPstmtInstEvtHist.setInt(14,
Integer.parseInt((String)dataobj.get(MQConstants.EVENT_MASTER_ID)));
mPstmtInstEvtHist.setString(15, eventname);
mPstmtInstEvtHist.setString(16, eventlvl);
mPstmtInstEvtHist.setString(17, evtMsg);
mPstmtInstEvtHist.setObject(18, jsonObj);
mPstmtInstEvtHist.setInt(19,
Integer.parseInt((String)dataobj.get(MQConstants.EVENT_RECV_DAY)));
mPstmtInstEvtHist.setTimestamp(20, colTs);
mPstmtInstEvtHist.setTimestamp(21, rcvTs);
mPstmtInstEvtHist.setString(22,
(String)dataobj.get(MQConstants.BLACKOUT_YN));
mPstmtInstEvtHist.setString(23,
(String)dataobj.get(MQConstants.MSG_FILTER_YN));
rtn = mPstmtInstEvtHist.executeUpdate();
if ( rtn == 1 ) {//NOPMD
Debug.getLogger().trace("Inserted Event into {} => {}, {}, {} "
,DatabaseTables.EVENT_HIST , mntrid, eventname, eventlvl);
} else {
Debug.getLogger().warn("Failed to insert Event into {} => {}",
DatabaseTables.EVENT_HIST, Debug.getString(jobj));
}
答案 0 :(得分:0)
可能是您的数据库中有基于触发器的分区,如in PostgreSQL manual所述。
它完全在DB端发生,除了它总是返回" 0行插入"。
检查数据库架构,以获取DatabaseTables.EVENT_HIST表中的分区触发器。