Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8053249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:46:54+00:00 2026-06-05T07:46:54+00:00

I have a table A. I insert data into table A through a user

  • 0

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.

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.

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.

If I try to insert the same data directly thorough SQL developer, the data gets inserted into the table.

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.

Can anyone please explain to me what could possibly cause this?

Not sure if this helps: stmt.executeUpdate(); returns 0 when the data is not inserted and a 1 when it’s inserted.

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<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);
    }
}

THE SQL STATEMENT:

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 = ?) ";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:46:55+00:00Added an answer on June 5, 2026 at 7:46 am

    Looks like you’re not inserting plain values, but a result of a select based on the parameters.
    What you are using is an INSERT ... SELECT () clause, so if the SELECT part does not return any rows, the INSERT won’t insert anything, and stmt.executeUpdate() will return 0. Find out why SELECT returns no rows.

    This may be due some triggers saving stuff in other tables when you do the insert into rpt_audit_transportation, but it’s just a guess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table with the following data (simplified): INSERT INTO `stores` (`storeId`,
I have a table Survey_Data_Response that is populated with an 'insert into' statement from
I have the following sample of data to insert into tables(from parent to child,
I have table that I insert data with following query (from c# code): INSERT
I have a requirement to insert 12600 data in one table. The data is
I have the following query to insert into a table BULK INSERT tblMain FROM
I do have a loop which store data into mysql... /connect to your database
I want to insert my data into a table depending on the value I
I have a long running insert transaction that inserts data into several related tables.
I have an INSERT query that is pulling data from two tables and inserting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.