JavaRanch » Java Forums »
Databases »
JDBC
| Author |
scrollable result sets
|
joe weakers
Ranch Hand
Joined: May 31, 2004
Posts: 38
|
|
I was hoping somebody might be able to help me with this. I keep encountering an error of the form java.lang.NullPointerException at oracle.jdbc.driver.ScrollableResultSet.close(ScrollableResultSet.java:149) This error is as a result of changing the format of the JDBC result set. Initially my code looked lke this: Statement stmt1 = cont.conn.createStatement(); //no errors OracleResultSet ors1 = (OracleResultSet)stmt1.executeQuery(query1); Now the code is as follows: Statement stmt1 = cont.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); OracleResultSet ors1 = (OracleResultSet)stmt1.executeQuery(query1); The error arises when i try to close ors1: ors1.close(); //error at this line Can anybody provide a solution to this for me. Thanks a lot, Joe P.S. the reason I am using Scrollable result sets is explained in my last post in this section.
|
 |
Raj Chila
Ranch Hand
Joined: Mar 18, 2004
Posts: 125
|
|
Hi, This is just a hint...closing the Resultset without actually reading it could be one issue?...but I have the Drivers do beheave differently than the standard jdbc apis promise.
|
 |
Rajendar Goud
Ranch Hand
Joined: Mar 06, 2002
Posts: 220
|
|
Hi, i too am facing the same exception when i use this result set. i had been using DB2 database with jdk1.4. its still not clear ,why this error is popping up. any help appreciated. Thanks, Raj
|
 |
Raj Chila
Ranch Hand
Joined: Mar 18, 2004
Posts: 125
|
|
Hi, After going through Rajendars post, I think my original post is misleading so I thought of testing it myself...and hey I did not get any such exceptions...infact tests on both MySQL and Oracle worked just fine..atleast they did not beheave the way you suggested. I have even tried the following scenarios. where the result set was empty. So there seems to be something wrong here. so you will probably have to look at where the null pointer is occuring, may be you can post your code here, completely.
|
 |
Rajendar Goud
Ranch Hand
Joined: Mar 06, 2002
Posts: 220
|
|
Hi Rajnikanth, sorry for adding in such huge code ,but this is what i am facing when i use the scrollable result set. [s0058367:::] ETListTableModelFactory.getETListTableModel : Error SQLException occurs...: com.ibm.db2.jcc.c.SQLException: Invalid operation: result set closed at com.ibm.db2.jcc.c.ca.T(ca.java:2682) at com.ibm.db2.jcc.c.ca.next(ca.java:221) at org.apache.commons.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:196) at com.db.ac.mccTracking.business.query.ETListTableModelFactory.setETListTableModel(ETListTableModelFactory.java:442 at com.db.ac.mccTracking.business.model.ETListBean.updateListData(ETListBean.java:828) at org.apache.jsp.ETListCtrl_jsp._jspService(ETListCtrl_jsp.java:126) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) Code: public static void setSomeListTableModel(SomeBean profile, SomeView listView, SomeFilter listFilter, SomeMultiFilter listMFilter, SomeSorting listSorting) throws DBSQLException, DBNotAuthorizedException, DBUnknownRoleException { WebServerCategory cat = (WebServerCategory) profile.getCat(); cat.debug("SomeTableModelFactory.setSomeListTableModel(): ENTER"); cat.debug("SomeTableModelFactory.setSomeListTableModel()-listView.getStartRow(): "+listView.getStartRow()); cat.debug("SomeTableModelFactory.setSomeListTableModel()-listView.getPageSize(): "+listView.getPageSize()); String user_ = profile.getUserName(); int role= Integer.parseInt(profile.getActRoleId()); long debugStartTime=0; int startRow = (listView.getStartRow()<0)?0:listView.getStartRow(); // startRow could never be negative !!! int pagesize = (listView.getPageSize()<0)?0:listView.getPageSize(); // pagesize could never be negative !!! String user = ""; // user couldn't be an empty string !!! (but it's only used with role 7 (PTV) if ( user_ == null ) { // Throw exception ###### ...SomeDBUnkownUserException } else { if ( user_.equals("") ) { // Throw exception ###### ...SomeDBUnkownUserException } else user = user_; } // Do the formating stuff: DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK); DecimalFormatSymbols dfs = new DecimalFormatSymbols( new Locale("en","GB") ); dfs.setGroupingSeparator('.'); dfs.setDecimalSeparator(','); // Show no decimals: DecimalFormat ff0 = new DecimalFormat("", dfs); ff0.setMinimumFractionDigits(minFractionDigits); ff0.setMaximumFractionDigits(minFractionDigits); ff0.setMinimumIntegerDigits(minIntegerDigits); Connection con = null; SomeListTableModel tableModel = null; int rowCounter = 0;//-1; int counter2 = 0; int colCounts = 10;// Anzahl Spalten... Object[] colNames = new Object[colCounts]; colNames[0] = "PrimaryKey"; colNames[1] = "Loc";// Location colNames[2] = "Area";// Business Area colNames[3] = "Type"; colNames[4] = "Info-1"; // security type colNames[5] = "Info-2"; // security code colNames[6] = "Info-3"; // security id colNames[7] = "Status";// actual status colNames[8] = "Date"; colNames[9] = "Deviation";//"Absolute Deviation"; Object[] row = null; Object[][] rowDatas = new Object[pagesize][colCounts]; try{ con = DBConnectionPool.getConnection(); // Scroll sensitive result set is not supported with this JDBC 2.0 DB2 driver version: //Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); Statement stmt = con.createStatement(); String query = ""; switch (role) { case Role.MCCG:// role: MCCG=1 case Role.TV:// role: TV=2 case Role.QA:// role: QA=6 case Role.PTV:// role: PTV=7 case Role.UserAdmin:// role: UserAdmin=9 case Role.UserApprover:// role: Approver=10 case Role.Admin:// role: Admin=8 case Role.ROTV:// role: ROTV=20 case Role.ROQA:// role: ROQA=21 query = getSelectStmt(profile, listFilter, listMFilter, listSorting); break; default: query = "Undefined role: no SELECT-Statement..."; throw new DBUnknownRoleException("Role "+role+" is unknown!"); } // end of switch(role)... // Display query for debug purpose: ##### if(cat.isDebugEnabled()){ cat.debug("SomeTableModelFactory.getSomeListTableModel()-query: "+query); } if(cat.isDebugEnabled()){ debugStartTime = System.currentTimeMillis(); } ResultSet rs = stmt.executeQuery(query); if(cat.isDebugEnabled()){ long t = System.currentTimeMillis() - debugStartTime; cat.debug("SomeTableModelFactory.getSomeListTableModel executeQuery duration= " + Long.toString(t) + " ms"); debugStartTime = System.currentTimeMillis(); } // rs.absolute() is not supported from DB2 database with this JDBC 2.0 driver // rs.absolute(startRow); while ( rs.next() ) { if ( rowCounter < startRow ) { rowCounter++; cat.debug("SomeTableModelFactory.getSomeListTableModel rowCounter = " + rowCounter); } else { cat.debug("SomeTableModelFactory.getSomeListTableModel -ELSE PART of ResultSet "); // SomeExpPrimaryKeyBean-value: SomemccKCode BigDecimal SomemccKCode = rs.getBigDecimal("MCC_GRK"); // traderBookLoc String traderBookLoc = rs.getString("TRADER_BOOK"); if ( rs.wasNull() ) traderBookLoc = Tab.Val_NULL; else traderBookLoc = traderBookLoc.trim(); rowDatas[counter2][1] = traderBookLoc; cat.debug("SomeTableModelFactory.getSomeListTableModel - ROWDATAS "); // SomeExpPrimaryKeyBean-values: versionNr BigDecimal versionNr = rs.getBigDecimal("VERSION_NO"); // SomeExpPrimaryKeyBean-values: versionStatus BigDecimal versionStatus = rs.getBigDecimal("VERSION_STATUS"); // SomeExpPrimaryKeyBean-values: systemId String systemId = rs.getString("SYSTEM_ID"); if ( rs.wasNull() ) systemId = Tab.Val_NULL; else systemId = systemId.trim(); // SomeExpPrimaryKeyBean-values: produktId String produktId = rs.getString("PRODUKT_ID"); if ( rs.wasNull() ) produktId = Tab.Val_NULL; else produktId = produktId.trim(); // SomeExpPrimaryKeyBean-values: exceptionTimestamp String exceptionTimestamp = rs.getString("EXCEPTION_TSP_CR"); if ( rs.wasNull() ) exceptionTimestamp = Tab.Val_NULL; else exceptionTimestamp = exceptionTimestamp.trim(); // SomeExpPrimaryKeyBean-values: act_status // status Integer status = new Integer(0); if (colCounts>7){ status = new Integer(rs.getInt("MAIN_STATUS")); //rowDatas[counter2][7] = ""; } //if (StatusHandler.getSingleton().isActive()) { // Add Status Handler Flags to SomeExpPrimaryKeyBean SomeExpPrimaryKeyBean epkb = new SomeExpPrimaryKeyBean( SomemccKCode, versionNr, versionStatus, systemId, produktId, exceptionTimestamp, status.intValue());// Fill with SomeExpPrimaryKeyBean... someSHMapper shm = new someSHMapper(); Integer mainSt= new Integer(rs.getInt(Tab.MAIN_STATUS)); shm.setMainStatus(mainSt.intValue()); Integer tradeS= new Integer(rs.getInt(Tab.TRADER_STATUS)); shm.setTraderStatus(tradeS.intValue()); Integer partyS= new Integer(rs.getInt(Tab.PARTY_STATUS)); shm.setPartyStatus(partyS.intValue()); Integer reproS= new Integer(rs.getInt(Tab.REPROC_STATUS)); shm.setReprocessingStatus(reproS.intValue()); Integer wf_Id = new Integer(rs.getInt(Tab.WORKFLOW_ID)); shm.setActiveIndicator(wf_Id.intValue()); cat.debug("shm = " + shm.toString()); epkb.setsomeSHMapper(shm); rowDatas[counter2][0] = epkb; cat.debug("\nStored EPKBean:\n"+epkb.toString()); //} else { //rowDatas[counter2][0] = new SomeExpPrimaryKeyBean( SomemccKCode, versionNr, versionStatus, systemId, produktId, exceptionTimestamp, status.intValue());// Fill with SomeExpPrimaryKeyBean... //} // RW 05.02.02: new formatting ResultSetMetaData rsmd = rs.getMetaData(); int size = rsmd.getColumnCount(); cat.debug("SomeTableModelFactory.getSomeListTableModel - ResultSetMetaData Size " + size); Vector mFields = new Vector(size); for (int i = 1; i <= size; i++) { mFields.add (rs.getObject(i)); } cat.debug("SomeTableModelFactory.getSomeListTableModel - Vector mFields Size " + mFields.size()); // formatting, XX 6.12.01 SomeTrade trade = new SomeTrade(); // Object[] fields = {null, null, null, null, null, null, sec_id, null, null, deviation}; // trade.getFields().clear(); // trade.getFields().addAll(Arrays.asList (fields)); cat.debug(" Instantiating SomeTDF to get the ProductId "); SomePR produkd = (SomePR) SomeTDF.getInstance( ).getProducts().getElementAt(Integer.parseInt( profile.getActProductId())); cat.debug(" SomeTableModelFactory Produkd " ); String prodDbLabel = listFilter==null?"":listFilter.getView(); if (prodDbLabel.equalsIgnoreCase("")) { prodDbLabel = produkd.getDbLabel(); } cat.debug(" SomeTableModelFactory Produkd Label " + prodDbLabel ); TradeCard card = (TradeCard) SomeTDF.getInstance().format( mFields, prodDbLabel).getOverviewSection( ).getComponents().get(0); // rowDatas[counter2][6] = card.getValueAt(0,6); // rowDatas[counter2][9] = card.getValueAt(0,9); // resize rowDatas if (counter2==0) { colCounts = card.getColumnCount(); Object oldKey = rowDatas[counter2][0]; rowDatas = new Object[pagesize][colCounts]; rowDatas[counter2][0] = oldKey; } cat.debug(" SomeTableModelFactory counter --1" ); for (int i=1;i<colCounts;i++) { rowDatas[counter2][i] = card.getValueAt(0,i); } // state index if (colCounts>7){ //rowDatas[counter2][7] = StatusHandler.getSingleton().getDescription(epkb.getsomeSHMapper().getFWS()) // + " " + epkb.getsomeSHMapper().additionalDescription(); rowDatas[counter2][7] = epkb.getsomeSHMapper().additionalDescription(); } cat.debug(" SomeTableModelFactory counter --2" ); // colNames colNames = new String[colCounts]; for (int i=0;i<colCounts;i++){ colNames[i] = card.getColumnName(i); } cat.debug(" SomeTableModelFactory counter --3" ); counter2++; if ( counter2 == pagesize) break; } } cat.debug(" Getting the counter for Incrementing the row "); rowCounter += counter2; cat.debug(" SomeTableModelFactory rowCounter -- 4 --" + rowCounter ); cat.debug(" SomeTableModelFactory Counter2 -- 5 --" + counter2 ); cat.debug(" SomeTableModelFactory pageSize -- 6 --" + pagesize ); while ( rs.next() ) rowCounter++; // ###################################################################### // TO BE SURE NOT RETURNING AN ARRAY WITH null VALUES: (!!!) // SHOULD BE CHANGED AS QUICK AS A SCROLLABLE RESULTSET IS AVAILABLE... // ###################################################################### if (counter2 != pagesize) { Object[][] rowDatas_tmp = new Object[counter2][colCounts]; for (int i = 0; i < counter2; i++) rowDatas_tmp[i] = rowDatas[i]; tableModel = new SomeListTableModel(rowDatas_tmp,colNames); cat.debug(" SomeTableModelFactory tableModel.getRowCount() --" + tableModel.getRowCount() ); } else tableModel = new SomeListTableModel(rowDatas,colNames); // ###################################################################### tableModel.setResultSetQuantity(rowCounter); if(cat.isDebugEnabled()){ long t = System.currentTimeMillis() - debugStartTime; cat.debug("SomeTableModelFactory.getSomeListTableModel :create Tablemodel duration= " + Long.toString(t) + " ms"); cat.debug("SomeTableModelFactory.getSomeListTableModel-Lines in ResultSet: "+rowCounter); } // Close ResultSet, PreparedStatement and Database Connection: rs.close(); stmt.close(); con.commit(); con.close(); con = null; } catch(SQLException SQLExcept) { if(cat.isEnabledFor(Priority.ERROR)){ cat.error("SomeTableModelFactory.getSomeListTableModel : Error SQLException occurs...: ", SQLExcept); } //System.out.println("SQLException occurs...: " + SQLExcept ); throw new DBSQLException("getETDetailTableModel() throws Unknown SQLException");//### } finally { if ( con != null ) { try{ con.rollback(); con.close(); con = null; } catch(SQLException SQLExcept) { if(cat.isEnabledFor(Priority.ERROR)){ cat.error("SomeTableModelFactory.getSomeListTableModel : Error SQLException occurs...: ", SQLExcept); } //System.out.println("SQLException occurs...: " + SQLExcept ); throw new DBSQLException("getETDetailTableModel() COULDN'T ROLLBACK/CLOSE CONNECTION!");//### } } } if(cat.isDebugEnabled()){ cat.debug("SomeTableModelFactory.setSomeListTableModel(): LEAVE"); } listView.setModel( tableModel ); return; } WHEN I UNCOMMENT THE CODE WITH THE SCROLLABLE RESULTSET,I GET THE ABOVE EXCEPTION.BUT IF I COMMENT AND RUN THE PROGRAM AS IT IS ,I GET A DIFFERENT EXCEPTION.ITS AS BELOW.ITS B/C OF DefaultTableModel WHICH THROWS THE BELOW EXCEPTION. java.lang.ArrayIndexOutOfBoundsException: 10 >= 10 at java.util.Vector.elementAt(Vector.java:432) at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:622) at com.db.ta.services.taglib.table.CellTag.setVariables(CellTag.java:47) at com.db.ta.services.taglib.table.CellTag.doStartTag(CellTag.java:37) at org.apache.jsp.ETListContent_jsp._jspService(ETListContent_jsp.java:238) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:595) 101781 [http-8080-Processor5] ERROR D1D1EC9BA674705C421C0C95681041F4 - ErrorToUser: java.lang.ArrayIndexOutOfBoundsException: 10 >= 10 at java.util.Vector.elementAt(Vector.java:432) at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:622) at com.db.ta.services.taglib.table.CellTag.setVariables(CellTag.java:47) at com.db.ta.services.taglib.table.CellTag.doStartTag(CellTag.java:37) at org.apache.jsp.ETListContent_jsp._jspService(ETListContent_jsp.java:238) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:595) THIS ArrayIndexOutOfBoundsException, I HAD OBSERVED MANY OTHERS FACING THE SAME WHEN WORKING WITH DefaultTableModel. COULD ANY ONE SUGGESST ANY SOLUTION PLS Thanks Raj
|
 |
Raj Chila
Ranch Hand
Joined: Mar 18, 2004
Posts: 125
|
|
Hi Raj, I went through the code in a blick, and I feel that you can point out in this code as a comment as to where this array index out of bounds is occurring? as far as I see you are interchangeably using colcounts which is fixed and mfields.size() which is dynamically generated based on the ResultSet Matadata.
|
 |
Rajendar Goud
Ranch Hand
Joined: Mar 06, 2002
Posts: 220
|
|
Thanks Rajanikanth, Here is the code with the exceptions being mentioned as COMMENTS.You can check for the following comments in the below code // RESULT SET CLOSED is occuring at the below line /* ARRAYINDEXOUTOFBOUNDS exception is occuring in the below loop i guess, as its in general related with DefaultTableModel class,but not with this code! */ public static void setSomeListTableModel(SomeBean profile, SomeView listView, SomeFilter listFilter, SomeMultiFilter listMFilter, SomeSorting listSorting) throws DBSQLException, DBNotAuthorizedException, DBUnknownRoleException { WebServerCategory cat = (WebServerCategory) profile.getCat(); cat.debug("SomeTableModelFactory.setSomeListTableModel(): ENTER"); cat.debug("SomeTableModelFactory.setSomeListTableModel()-listView.getStartRow(): "+listView.getStartRow()); cat.debug("SomeTableModelFactory.setSomeListTableModel()-listView.getPageSize(): "+listView.getPageSize()); String user_ = profile.getUserName(); int role= Integer.parseInt(profile.getActRoleId()); long debugStartTime=0; int startRow = (listView.getStartRow()<0)?0:listView.getStartRow(); // startRow could never be negative !!! int pagesize = (listView.getPageSize()<0)?0:listView.getPageSize(); // pagesize could never be negative !!! String user = ""; // user couldn't be an empty string !!! (but it's only used with role 7 (PTV) if ( user_ == null ) { // Throw exception ###### ...SomeDBUnkownUserException } else { if ( user_.equals("") ) { // Throw exception ###### ...SomeDBUnkownUserException } else user = user_; } // Do the formating stuff: DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK); DecimalFormatSymbols dfs = new DecimalFormatSymbols( new Locale("en","GB") ); dfs.setGroupingSeparator('.'); dfs.setDecimalSeparator(','); // Show no decimals: DecimalFormat ff0 = new DecimalFormat("", dfs); ff0.setMinimumFractionDigits(minFractionDigits); ff0.setMaximumFractionDigits(minFractionDigits); ff0.setMinimumIntegerDigits(minIntegerDigits); Connection con = null; SomeListTableModel tableModel = null; int rowCounter = 0;//-1; int counter2 = 0; int colCounts = 10;// Anzahl Spalten... Object[] colNames = new Object[colCounts]; colNames[0] = "PrimaryKey"; colNames[1] = "Loc";// Location colNames[2] = "Area";// Business Area colNames[3] = "Type"; colNames[4] = "Info-1"; // security type colNames[5] = "Info-2"; // security code colNames[6] = "Info-3"; // security id colNames[7] = "Status";// actual status colNames[8] = "Date"; colNames[9] = "Deviation";//"Absolute Deviation"; Object[] row = null; Object[][] rowDatas = new Object[pagesize][colCounts]; try{ con = DBConnectionPool.getConnection(); // Scroll sensitive result set is not supported with this JDBC 2.0 DB2 driver version: //Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); Statement stmt = con.createStatement(); String query = ""; switch (role) { case Role.MCCG:// role: MCCG=1 case Role.TV:// role: TV=2 case Role.QA:// role: QA=6 case Role.PTV:// role: PTV=7 case Role.UserAdmin:// role: UserAdmin=9 case Role.UserApprover:// role: Approver=10 case Role.Admin:// role: Admin=8 case Role.ROTV:// role: ROTV=20 case Role.ROQA:// role: ROQA=21 query = getSelectStmt(profile, listFilter, listMFilter, listSorting); break; default: query = "Undefined role: no SELECT-Statement..."; throw new DBUnknownRoleException("Role "+role+" is unknown!"); } // end of switch(role)... // Display query for debug purpose: ##### if(cat.isDebugEnabled()){ cat.debug("SomeTableModelFactory.getSomeListTableModel()-query: "+query); } if(cat.isDebugEnabled()){ debugStartTime = System.currentTimeMillis(); } ResultSet rs = stmt.executeQuery(query); if(cat.isDebugEnabled()){ long t = System.currentTimeMillis() - debugStartTime; cat.debug("SomeTableModelFactory.getSomeListTableModel executeQuery duration= " + Long.toString(t) + " ms"); debugStartTime = System.currentTimeMillis(); } // rs.absolute() is not supported from DB2 database with this JDBC 2.0 driver // rs.absolute(startRow); while ( rs.next() ) { if ( rowCounter < startRow ) { rowCounter++; cat.debug("SomeTableModelFactory.getSomeListTableModel rowCounter = " + rowCounter); } else { cat.debug("SomeTableModelFactory.getSomeListTableModel -ELSE PART of ResultSet "); // SomeExpPrimaryKeyBean-value: SomemccKCode BigDecimal SomemccKCode = rs.getBigDecimal("MCC_GRK"); // traderBookLoc String traderBookLoc = rs.getString("TRADER_BOOK"); if ( rs.wasNull() ) traderBookLoc = Tab.Val_NULL; else traderBookLoc = traderBookLoc.trim(); rowDatas[counter2][1] = traderBookLoc; cat.debug("SomeTableModelFactory.getSomeListTableModel - ROWDATAS "); // SomeExpPrimaryKeyBean-values: versionNr BigDecimal versionNr = rs.getBigDecimal("VERSION_NO"); // SomeExpPrimaryKeyBean-values: versionStatus BigDecimal versionStatus = rs.getBigDecimal("VERSION_STATUS"); // SomeExpPrimaryKeyBean-values: systemId String systemId = rs.getString("SYSTEM_ID"); if ( rs.wasNull() ) systemId = Tab.Val_NULL; else systemId = systemId.trim(); // SomeExpPrimaryKeyBean-values: produktId String produktId = rs.getString("PRODUKT_ID"); if ( rs.wasNull() ) produktId = Tab.Val_NULL; else produktId = produktId.trim(); // SomeExpPrimaryKeyBean-values: exceptionTimestamp String exceptionTimestamp = rs.getString("EXCEPTION_TSP_CR"); if ( rs.wasNull() ) exceptionTimestamp = Tab.Val_NULL; else exceptionTimestamp = exceptionTimestamp.trim(); // SomeExpPrimaryKeyBean-values: act_status // status Integer status = new Integer(0); if (colCounts>7){ status = new Integer(rs.getInt("MAIN_STATUS")); //rowDatas[counter2][7] = ""; } //if (StatusHandler.getSingleton().isActive()) { // Add Status Handler Flags to SomeExpPrimaryKeyBean SomeExpPrimaryKeyBean epkb = new SomeExpPrimaryKeyBean( SomemccKCode, versionNr, versionStatus, systemId, produktId, exceptionTimestamp, status.intValue());// Fill with SomeExpPrimaryKeyBean... someSHMapper shm = new someSHMapper(); Integer mainSt= new Integer(rs.getInt(Tab.MAIN_STATUS)); shm.setMainStatus(mainSt.intValue()); Integer tradeS= new Integer(rs.getInt(Tab.TRADER_STATUS)); shm.setTraderStatus(tradeS.intValue()); Integer partyS= new Integer(rs.getInt(Tab.PARTY_STATUS)); shm.setPartyStatus(partyS.intValue()); Integer reproS= new Integer(rs.getInt(Tab.REPROC_STATUS)); shm.setReprocessingStatus(reproS.intValue()); Integer wf_Id = new Integer(rs.getInt(Tab.WORKFLOW_ID)); shm.setActiveIndicator(wf_Id.intValue()); cat.debug("shm = " + shm.toString()); epkb.setsomeSHMapper(shm); rowDatas[counter2][0] = epkb; cat.debug("\nStored EPKBean:\n"+epkb.toString()); //} else { //rowDatas[counter2][0] = new SomeExpPrimaryKeyBean( SomemccKCode, versionNr, versionStatus, systemId, produktId, exceptionTimestamp, status.intValue());// Fill with SomeExpPrimaryKeyBean... //} // RW 05.02.02: new formatting ResultSetMetaData rsmd = rs.getMetaData(); int size = rsmd.getColumnCount(); cat.debug("SomeTableModelFactory.getSomeListTableModel - ResultSetMetaData Size " + size); Vector mFields = new Vector(size); for (int i = 1; i <= size; i++) { mFields.add (rs.getObject(i)); } cat.debug("SomeTableModelFactory.getSomeListTableModel - Vector mFields Size " + mFields.size()); // formatting, XX 6.12.01 SomeTrade trade = new SomeTrade(); // Object[] fields = {null, null, null, null, null, null, sec_id, null, null, deviation}; // trade.getFields().clear(); // trade.getFields().addAll(Arrays.asList (fields)); cat.debug(" Instantiating SomeTDF to get the ProductId "); SomePR produkd = (SomePR) SomeTDF.getInstance( ).getProducts().getElementAt(Integer.parseInt( profile.getActProductId())); cat.debug(" SomeTableModelFactory Produkd " ); String prodDbLabel = listFilter==null?"":listFilter.getView(); if (prodDbLabel.equalsIgnoreCase("")) { prodDbLabel = produkd.getDbLabel(); } cat.debug(" SomeTableModelFactory Produkd Label " + prodDbLabel ); TradeCard card = (TradeCard) SomeTDF.getInstance().format( mFields, prodDbLabel).getOverviewSection( ).getComponents().get(0); // rowDatas[counter2][6] = card.getValueAt(0,6); // rowDatas[counter2][9] = card.getValueAt(0,9); // resize rowDatas if (counter2==0) { colCounts = card.getColumnCount(); Object oldKey = rowDatas[counter2][0]; rowDatas = new Object[pagesize][colCounts]; rowDatas[counter2][0] = oldKey; } cat.debug(" SomeTableModelFactory counter --1" ); for (int i=1;i<colCounts;i++) { rowDatas[counter2][i] = card.getValueAt(0,i); } // state index if (colCounts>7){ //rowDatas[counter2][7] = StatusHandler.getSingleton().getDescription(epkb.getsomeSHMapper().getFWS()) // + " " + epkb.getsomeSHMapper().additionalDescription(); rowDatas[counter2][7] = epkb.getsomeSHMapper().additionalDescription(); } cat.debug(" SomeTableModelFactory counter --2" ); // colNames colNames = new String[colCounts]; for (int i=0;i<colCounts;i++){ colNames[i] = card.getColumnName(i); } cat.debug(" SomeTableModelFactory counter --3" ); counter2++; if ( counter2 == pagesize) break; } } cat.debug(" Getting the counter for Incrementing the row "); rowCounter += counter2; cat.debug(" SomeTableModelFactory rowCounter -- 4 --" + rowCounter ); cat.debug(" SomeTableModelFactory Counter2 -- 5 --" + counter2 ); cat.debug(" SomeTableModelFactory pageSize -- 6 --" + pagesize ); // RESULT SET CLOSED is occuring at the below line while ( rs.next() ) rowCounter++; // ###################################################################### // TO BE SURE NOT RETURNING AN ARRAY WITH null VALUES: (!!!) // SHOULD BE CHANGED AS QUICK AS A SCROLLABLE RESULTSET IS AVAILABLE... // ###################################################################### /* ARRAYINDEXOUTOFBOUNDS exception is occuring in the below loop i guess, as its in general related with DefaultTableModel class,but not with this code! */ if (counter2 != pagesize) { Object[][] rowDatas_tmp = new Object[counter2][colCounts]; for (int i = 0; i < counter2; i++) rowDatas_tmp[i] = rowDatas[i]; tableModel = new SomeListTableModel(rowDatas_tmp,colNames); cat.debug(" SomeTableModelFactory tableModel.getRowCount() --" + tableModel.getRowCount() ); } else tableModel = new SomeListTableModel(rowDatas,colNames); // ###################################################################### tableModel.setResultSetQuantity(rowCounter); if(cat.isDebugEnabled()){ long t = System.currentTimeMillis() - debugStartTime; cat.debug("SomeTableModelFactory.getSomeListTableModel :create Tablemodel duration= " + Long.toString(t) + " ms"); cat.debug("SomeTableModelFactory.getSomeListTableModel-Lines in ResultSet: "+rowCounter); } // Close ResultSet, PreparedStatement and Database Connection: rs.close(); stmt.close(); con.commit(); con.close(); con = null; } catch(SQLException SQLExcept) { if(cat.isEnabledFor(Priority.ERROR)){ cat.error("SomeTableModelFactory.getSomeListTableModel : Error SQLException occurs...: ", SQLExcept); } //System.out.println("SQLException occurs...: " + SQLExcept ); throw new DBSQLException("getETDetailTableModel() throws Unknown SQLException");//### } finally { if ( con != null ) { try{ con.rollback(); con.close(); con = null; } catch(SQLException SQLExcept) { if(cat.isEnabledFor(Priority.ERROR)){ cat.error("SomeTableModelFactory.getSomeListTableModel : Error SQLException occurs...: ", SQLExcept); } //System.out.println("SQLException occurs...: " + SQLExcept ); throw new DBSQLException("getETDetailTableModel() COULDN'T ROLLBACK/CLOSE CONNECTION!");//### } } } if(cat.isDebugEnabled()){ cat.debug("SomeTableModelFactory.setSomeListTableModel(): LEAVE"); } listView.setModel( tableModel ); return; } but rajanikanth, am not sure why the ResultSet closed exception is occuring? Thanks, Raj
|
 |
Raj Chila
Ranch Hand
Joined: Mar 18, 2004
Posts: 125
|
|
hi, The Error that the resultset is closed must be because, you are calling on the while(rs.next()) immediately after the result has been read completely in the first loop. you can avoid this code here...and increment the row counter in the main loop that you read the result set from. while ( rs.next() ) rowCounter++; this should solve the resultset problem, and somehow the Array index problem is also related to this....please try that first, that is removing the second while(rs.next()) and incrementing the rowcounter in the main loop only.
|
 |
Rajendar Goud
Ranch Hand
Joined: Mar 06, 2002
Posts: 220
|
|
Rajanikanth, When i try the code with the Scrollable ResultSet and the changes which u suggested, i get the following exception.i have the dbjava.zip and the db2jcc.jar in my classpath and also in tomcats WEB-INF/lib and WEB-INF/common folders. com.ibm.db2.jcc.c.SQLException: DB2 SQL error: SQLCODE: -243, SQLSTATE: 36001, SQLERRMC: SQL_CURLH200C1 at com.ibm.db2.jcc.c.cf.e(cf.java:1108) at com.ibm.db2.jcc.c.cf.a(cf.java:882) at com.ibm.db2.jcc.c.cf.c(cf.java:870) at com.ibm.db2.jcc.a.be.g(be.java:119) at com.ibm.db2.jcc.a.be.a(be.java:40) at com.ibm.db2.jcc.a.s.a(s.java:31) at com.ibm.db2.jcc.a.bq.g(bq.java:103) at com.ibm.db2.jcc.c.cf.g(cf.java:866) at com.ibm.db2.jcc.c.cf.a(cf.java:1330) at com.ibm.db2.jcc.c.cf.executeQuery(cf.java:262) at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:188) at com.db.ac.mccTracking.business.query.ETListTableModelFactory.setETListTableModel(ETListTableModelFactory.java:199) at com.db.ac.mccTracking.business.model.ETListBean.updateListData(ETListBean.java:828) at org.apache.jsp.ETListCtrl_jsp._jspService(ETListCtrl_jsp.java:126) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534) WHEN I COMMENT OUT THE SCROLLABLE RESULTSET AND USE THE GENERAL RESULTSET, THE 'RESULTSET CLOSED' EXCEPTION IS GONE BUT I STILL FACE THE ArrayIndexOutOfBoundsException. LOOKS LIKE ITS NOT RELATED WITH THE CODE AS I SAID.ITS WITH THE TABLEMODEL. PLS SEE THE BELOW LINKS WHICH I FOUND IN SOMEOTHER SITES WHO FACED THE SAME EXCEPTION. http://forums.devshed.com/archive/t-104626 It may not be exactly the same as my code but i too am using the same sort of classes like my class in which i extended DefaultTableModel Thanks, Raj
|
 |
Rajendar Goud
Ranch Hand
Joined: Mar 06, 2002
Posts: 220
|
|
Any more updates on this pls? -Raj
|
 |
 |
|
|
subject: scrollable result sets
|
|
|
|