Note that there are some explanatory texts on larger screens.

plurals
  1. POJava PreparedStatement RETURN_GENERATED_KEYS not working
    primarykey
    data
    text
    <p>I am trying to get the identity column returned to my java program when doing a SQL insert. I am getting the following error when running the code </p> <pre><code> Uncaught exception thrown in one of the service methods of the servlet: Cocoon. Exception thrown : java.lang.AbstractMethodError: java/sql /Connection.prepareStatement(Ljava/lang/String;I)Ljava/sql/PreparedStatement; </code></pre> <p>Here is the code I am running.</p> <pre><code>private void insertUserInputParameters(ReportData rptData){ UserInputParameters userParams = rptData.getUserInputData(); StringBuilder sql = new StringBuilder(); PreparedStatement pstmt = null; ResultSet rs = null; int userDataId = -1; //Get a database connection. sl = ServiceLocator.getInstance(); ds = sl.getDataSource("jdbc/collegeguide"); con = ds.getConnection(); con.setReadOnly(false); sql.append("insert into cpgusrdtaf (statecd, addr1, addr2, city, state, "); sql.append("zipcode, dependent, shdindic, marstatus, residency, prntatge, "); sql.append("fincome, mincome, pincome, taxspaid, taxreturn, elig1040, "); sql.append("gincome, pcash, inetwrth, bnetwrth, pbenefit, paddlinf, "); sql.append("puntax, pdslcwrk, smstatus, sresidncy, studtr, stud1040, "); sql.append("sadjinc, sincome, spincome, sdslcwrk, studtax, scash, "); sql.append("sinvest, snetwrth, saddlinf, suntax, househld, nmbrsch, "); sql.append("studact, studsat, schools, housing) "); sql.append("values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, "); sql.append("?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); //This line of code is where I get the error** pstmt = con.prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS); //If I remove the 'Statement.RETURN_GENERATED_KEYS' I do not get the error.** pstmt = con.prepareStatement(sql.toString()); setStatementValues(pstmt, userParams); pstmt.executeUpdate(); rs = pstmt.getGeneratedKeys(); if(rs.next()){ userDataId = rs.getInt(1); } </code></pre> <p>I am not allowed to use stored procedures, so I cannot go that route. Any help would be greatly appreciated</p> <p>I am using java 1.5</p> <p>Thanks in advance Doug</p>
    singulars
    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.
 

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