Note that there are some explanatory texts on larger screens.

plurals
  1. POData does not get inserted into the table sometime
    primarykey
    data
    text
    <p>I have a table A. I insert data into table A through a user interface. Table A has an ID(primary key), which is generated using a sequence, and 16 other columns. One of the column is called cntrct_no. </p> <p>When I try to insert data into the table through UI, it works fine the first time. I check the table A and all the data are there. </p> <p>But when I try to insert the same data again without changing anything, it looks like the data is getting added to the table and I do not get any errors. But when I check table A, the data inserted the second time is not there. </p> <p>If I try to insert the same data directly thorough SQL developer, the data gets inserted into the table. </p> <p>The weird thing is if I just change the value of the cntrct_no in the UI and leave rest of the data same, the data gets inserted. </p> <p>Can anyone please explain to me what could possibly cause this? </p> <p>Not sure if this helps: stmt.executeUpdate(); returns 0 when the data is not inserted and a 1 when it's inserted. </p> <pre><code>public void writeToAudit(String contractNo, String tripNo, String tripEffDate, String tripDiscDate, String transpModeId, String userId, String transType, AplLeg[] legs) { final Session session = HibernateUtil.getSession(); Connection con = null; con = session.connection(); PreparedStatement stmt = null; PreparedStatement stmtSelId = null; ResultSet rs = null; long nextId = -1; int i=0; try { for(i=0;i&lt;legs.length;i++) { String sqlNextId = "SELECT rpt_audit_transportation_seq.NEXTVAL as seqval FROM DUAL"; stmtSelId = con.prepareStatement(sqlNextId, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); rs = stmtSelId.executeQuery(); rs.last(); final int rows = rs.getRow(); if (rows == 0){ nextId = -1; } rs.beforeFirst(); rs.next(); nextId = rs.getInt(1); if(nextId==-1) throw new SQLException("Cannot get next val from rpt_audit_transportation sequence."); stmt = con.prepareStatement(WRITE_TO_AUDIT_DML); stmt.setLong(1, nextId); stmt.setString(2, userId.toUpperCase()); stmt.setString(3, transType); stmt.setString(4, contractNo); stmt.setString(5, tripNo); stmt.setInt(6, Integer.parseInt(transpModeId)); stmt.setString(7, tripEffDate); stmt.setString(8, tripDiscDate); stmt.setLong(9, legs[i].getLegId().longValue()); int temp = stmt.executeUpdate(); con.commit(); } stmt.close(); } catch (Exception e) { } finally { closeConnection(session, con, stmtSelId, rs); } } </code></pre> <p>THE SQL STATEMENT: </p> <pre><code>private static final String WRITE_TO_AUDIT_DML = "INSERT INTO rpt_audit_transportation " + "(audit_id, audit_date, audit_process, audit_userid, " + "audit_trans_type, audit_route_no, audit_trip_no, " + "audit_eff_dt, audit_disc_dt, audit_orig_facility_id, " + "audit_dest_facility_id, audit_arvl_tm, audit_dprt_tm, " + "audit_leg_seq_no, audit_freq_id, audit_trnsp_mode_id) " + "(SELECT ?, " + // audit id "SYSDATE, " + "'TOPS_UI', " + "?, " + // userId "?, " + "rte.cntrct_no, " + "trp.trip_no, " + "rte.cntrct_eff_dt, " + "rte.cntrct_disc_dt, " + "NVL(leg.orig_facility_id, trp.orig_fac_id), " + "NVL(leg.dest_facility_id, trp.dest_fac_id), " + "NVL(leg.arvl_tm, trp.arvl_tm), " + "NVL(leg.dprt_tm, trp.dprt_tm), " + "leg.leg_seq, " + "trp.freq_id, " + "rte.trnsp_mode_id " + "FROM apl_contract rte, " + "apl_trip trp, " + "apl_leg leg " + "WHERE rte.cntrct_no = ? " + // contract id "AND trp.trip_no = ? " + // trip no "AND rte.trnsp_mode_id = ? " + // transp mode id "AND rte.cntrct_locked_ind = 'N' " + "AND trp.trip_eff_dt = to_date(?,'MM/DD/YYYY') " + // trip eff date "AND trp.trip_disc_dt = to_date(?,'MM/DD/YYYY') " + // trip disc date "AND trp.cntrct_id = rte.cntrct_id " + "AND leg.trip_id = trp.trip_id " + "AND leg.leg_id = ?) "; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload