PreparedStatements ArrayIndexOutOfBoundsException

We are running our application on a WebLogic 5.1(sp 9)server using JDK
1.2.2 on an HP Unix box. We use a weblogic.jdbc.oci.Driver to access
an Oracle 8.1.5 database. The issue we have is with creating a
dynamic prepared statement. The prepared statement is a select
statement generated from a selection of account numbers on a web page.
First the prepared statement is dynamically built based on the number
of account numbers selected. For example, 'Select * from tablename
where accountnbr IN (?,?,?.......)'. In a while loop, a '?' is added
for each accountnbr selected. Next, in another while loop, a
variable is bound to each parameter by using a while loop (ie:
ps.setString(i++, accountnbrArray). The prepared statement is then
executed. This works fine so long as there is under 512 accounts
selected. However, once 512 or more accounts are selected, we get an
error. While looping through and binding the variables using the
setString method, the application throws an
ArrayIndexOutOfBoundsException in this method on the 512th parameter
every time. Can anyone help me out with what/why this is happening?
Thanks for your help.

Hi Don,
Could you post a stacktrace of the exception you're getting?
FYI, SP9 had a problem with PreparedStatement cache, so you
may want to try turning it off by putting STATEMENT_CACHE=0
in the connection pool properties.
Regards,
Slava Imeshev
"Don" <[email protected]> wrote in message
news:[email protected]..
We are running our application on a WebLogic 5.1(sp 9)server using JDK
1.2.2 on an HP Unix box. We use a weblogic.jdbc.oci.Driver to access
an Oracle 8.1.5 database. The issue we have is with creating a
dynamic prepared statement. The prepared statement is a select
statement generated from a selection of account numbers on a web page.
First the prepared statement is dynamically built based on the number
of account numbers selected. For example, 'Select * from tablename
where accountnbr IN (?,?,?.......)'. In a while loop, a '?' is added
for each accountnbr selected. Next, in another while loop, a
variable is bound to each parameter by using a while loop (ie:
ps.setString(i++, accountnbrArray). The prepared statement is then
executed. This works fine so long as there is under 512 accounts
selected. However, once 512 or more accounts are selected, we get an
error. While looping through and binding the variables using the
setString method, the application throws an
ArrayIndexOutOfBoundsException in this method on the 512th parameter
every time. Can anyone help me out with what/why this is happening?
Thanks for your help.

Similar Messages

  • PreparedStatement and executeBatch()

    Hi,
    I am trying to insert records into the database using the addBatch() and executeBatch() methods. I am using PreparedStatement. And I am trying to insert 52 records at a time.
    I have the records in an array, and I am looping through the array, setting the parameters for the prepared statement and doing addBatch(). And finally when I come out of the loop I call preparedStatement.executeBatch().
    int[] updateCounts = ps.executeBatch();
    Here it is throwing out the ArrayIndexOutOfBoundsException. Anybody has any idea why this is happening? This works fine with the Statement object, but it is with the PreparedStatement that I am having this problem. I am using JDK 1.3. My database is DB2 UDB 7.1 and my driver is IBM DB2 ODBC Driver.
    thanks in advance,
    Nish

    Hi,
    Thanks for the reply... Here is my code.
    public void insertNetFcst(Connection con, PreparedStatement ps, NetForecast[] arrNF){
    Connection conn = con;
    PreparedStatement psIns = ps;
    NetForecast[] arrNet = new NetForecast[52]; //Array of objects of type NetForecast
    arrNet = arrNF;
    int intLen = 0;
    intLen = arrNet.length;
    try{                    
    for (int ins = 0; ins < intLen; ins++){
    NetForecast nFct = new NetForecast();
    nFct = (NetForecast)arrNet[ins];
    psIns.setString(1, nFct.getCorpId());
    psIns.setString(2, nFct.getDivId());
    psIns.setString(3, nFct.getShipWhseId());
    psIns.setString(4, nFct.getRecvWhseId());
    psIns.setDouble(5, nFct.getUpcId());
    psIns.setInt(6, nFct.getYearId());
    psIns.setInt(7, nFct.getWeekNbr());
    psIns.setInt(8, nFct.getDemandQty());
    psIns.setString(9, nFct.getUomCode());
    psIns.setInt(10, nFct.getReqdYear());
    psIns.setInt(11, nFct.getReqdWeek());
    psIns.setString(12, nFct.getFcstTypeInd());
    psIns.setTimestamp(13, new Timestamp(System.currentTimeMillis()));
    psIns.addBatch();
    int[] updateCounts = psIns.executeBatch();
    //I am getting the exception at this line... where I call executeBatch()
    conn.commit();
    catch(BatchUpdateException b){
    System.err.println("SQLException: " + b.getMessage());
    System.err.println("SQLState: " + b.getSQLState());
    System.err.println("Message: " + b.getMessage());
    System.err.println("Vendor: " + b.getErrorCode());
    System.err.print("Update counts: ");
    int [] updateCounts = b.getUpdateCounts();
    for (int i = 0; i < updateCounts.length; i++) {
    System.err.print(updateCounts[i] + " ");
    b.printStackTrace();
    catch(SQLException insExp){
    System.out.println("Duplicate record exception..." + insExp);
    thanks,
    Nish

  • PreparedStatement with 56cols in batch giving ArrayIndexOutOfBoundException

    Hello All,
    PreparedStatement trying to do bath update/inserts in table with 56 columns is giving ArrayIndexOutOfBoundException sporadically with 11.2.0.3 driver. Is it related to Bug 6396242,which was supposed fix in 11.1.0.7.0?
    Here is the stackTrace:
    EXCEPTION ENCOUNTERED:
    java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 4
    at oracle.jdbc.driver.VarnumBinder.big5pow(OraclePreparedStatement.java:15348)
    at oracle.jdbc.driver.VarnumBinder.constructPow52(OraclePreparedStatement.java:15420)
    at oracle.jdbc.driver.VarnumBinder.dtoa(OraclePreparedStatement.java:15884)
    at oracle.jdbc.driver.DoubleBinder.bind(OraclePreparedStatement.java:17239)
    at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:3137)
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2355)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3579)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3665)

    Welcome to the forum!
    >
    PreparedStatement trying to do bath update/inserts in table with 56 columns is giving ArrayIndexOutOfBoundException sporadically with 11.2.0.3 driver. Is it related to Bug 6396242,which was supposed fix in 11.1.0.7.0?
    >
    How would anyone know? You haven't posted the 4 digit Oracle version, the JDK version, the platform or any code for anyone to look at.
    Post the code and other information people need to try to help you.

  • urgent database PreparedStatement problem

    i have tried the following codes for many many times but it still cant work does anyone know why? please help, thank you.
    codes segment:
    PreparedStatement update = connection.prepareStatement(
    "UPDATE OutgoingQueue SET statusEmulator = ? and dateOut = ? WHERE receiverContact = ? and receiverLocation='?' and dateProcessed= ?");
    update.setBoolean(1,msg.getStatus());
    update.setTimestamp(2,dateSent);
    update.setInt(3,contact);
    update.setString(4,location);
    update.setTimestamp(5,dateProcessed);
    update.executeUpdate();
    stacktrace:
    java.lang.ArrayIndexOutOfBoundsException
         at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(JdbcOdbcPreparedStatement.java:1026)
         at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setTimestamp(JdbcOdbcPreparedStatement.java:908)
         at DBOutgoingQueue.updateStatus(DBOutgoingQueue.java:124)
         at DBOutgoingQueue.main(DBOutgoingQueue.java:191)

    Hi,
    First of all the SQL query it self is wrong.
    You have given
    "UPDATE OutgoingQueue SET statusEmulator = ? and dateOut = ? WHERE receiverContact = ? and receiverLocation='?' and dateProcessed= ?");
    For Update query you need to give the values camma seperated and not to use "and".
    "UPDATE OutgoingQueue SET statusEmulator = ?,dateOut = ? WHERE receiverContact = ? and receiverLocation='?' and dateProcessed= ?"
    Simillarly before executing the query from java try to executed the same query with values from Oracle.
    Regards,
    DARMA

  • ArrayIndexOutOfBoundsException when 10g create prepareStatement

    Hey Guys!!
    Environment:
    -Oracle 10g Enterprise 10.2.0.1
    -JDBC Driver 10.2.0.1
    Error generation at prepareStatement creation because use query piece such as lower part.
    [java source]==========================================
    String sql = "UPDATE CUS_CTM_ACT SET CTMNO = CTMNO , BKCD = BKCD, ACTNO = ACTNO , " +
                   "BK_BRCD = ?, " +
                   "US_YN = ?, " +
                   "BK_BRNM = ?, " +
                   "DPSNM = ?, " +
                   "RGTDT = ?, " +
                   "CNF_YN = ?, " +
                   "MNTR_ACT_YN = ?, " +
                   "FNL_USDT = ?, " +
                   "INP_USR_ID = ?, " +
                   "INP_DTHMS = ? " +
                   "WHERE CTMNO = :aa AND BKCD = :cc AND ACTNO = :dd ";
              PreparedStatement pstmt = conn.prepareStatement(sql);
    [error log]=======================================
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 10
    at oracle.jdbc.driver.OracleSql.computeBasicInfo(OracleSql.java:936)
    at oracle.jdbc.driver.OracleSql.getSqlKind(OracleSql.java:608)
    at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:1195)
    at oracle.jdbc.driver.T4CPreparedStatement.<init>(T4CPreparedStatement.java:29)
    at oracle.jdbc.driver.T4CDriverExtension.allocatePreparedStatement(T4CDriverExtension.java:70)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:970)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:865)
    at oracle.jdbc.OracleConnectionWrapper.prepareStatement(OracleConnectionWrapper.java:92)
    At 9i jdbc, act there is no error.(same query....)
    If do as follows, error does not become.
    ============
    String sql = "UPDATE CUS_CTM_ACT SET CTMNO = CTMNO , BKCD = BKCD, ACTNO = ACTNO , " +
                   "BK_BRCD = :xx, " +
                   "US_YN = ?, " +
                   "BK_BRNM = ?, " +
                   "DPSNM = ?, " +
                   "RGTDT = ?, " +
                   "CNF_YN = ?, " +
                   "MNTR_ACT_YN = ?, " +
                   "FNL_USDT = ?, " +
                   "INP_USR_ID = ?, " +
                   "INP_DTHMS = ? " +
                   "WHERE CTMNO = :aa AND BKCD = :cc AND ACTNO = :dd ";
    PreparedStatement pstmt = conn.prepareStatement(sql);
    =============================================
    I will thank very if inform solution or contents that is worth.
    I thank beforehand.
    p.s. I must use colon certainly at parameter binding at development.
    Message was edited by:
    legume2

    Hi Legume2,
    I was on a look-out for a solution to an error i was stuck with and saw ur post in this oracle forum. Were you able to solve your issue? U somehow wud have solved that one as its almost a couple of yrs now....
    Well, this is my stack trace .... Lemme know if you have any solution for this??
    this happens to me here
    pstUpdate = connDbConn.prepareStatement(strQuery);
    and for the query,
    sbQuery.append("update login set login_id = '");
    sbQuery.append(strLoginID);
    sbQuery.append("' ");
    sbQuery.append(" where ");
    sbQuery.append(" employee_no = '");
    sbQuery.append(strEmpID);
    sbQuery.append("'");
    strQuery = sbQuery.toString();
    Env. - Oracle 10g and JDBC 3.0 (Connection Pooling)
    ERROR STACK TRACE
    17:54:28,884 ERROR [STDERR] java.sql.SQLException: Connection Closed.
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
         at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:868)
         at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:787)
         at oracle.jdbc.OracleConnectionWrapper.prepareStatement(OracleConnectionWrapper.java:92)
         at com.online.app.dao.LoginDAO.login(LoginDAO.java:341)
         at com.online.app.business.Login.login(Login.java:64)
         at com.online.app.ejb.LoginFacadeBean.login(LoginFacadeBean.java:211)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
         at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
         at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
         at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
         at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:267)
         at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128)
         at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
         at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
         at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
         at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
         at org.jboss.ejb.Container.invoke(Container.java:700)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
         at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:101)
         at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:90)
         at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
         at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
         at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:100)
         at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
         at $Proxy78.login(Unknown Source)
         at com.online.app.web.helper.LoginHelper.login(LoginHelper.java:132)
         at com.online.app.web.controller.GeneralController.execute(GeneralController.java:56)
         at com.online.app.web.servlet.MediatorServlet.executeAction(MediatorServlet.java:227)
         at com.online.app.web.servlet.MediatorServlet.doPost(MediatorServlet.java:145)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:197)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
         at java.lang.Thread.run(Thread.java:534)

  • Oracle ArrayIndexOutOfBoundsException on rs.getString

    I receive the following error calling
    ts.getString method with oracle thin jdbc driver.
    Do you have any Idea?
    Thanks..
    Ivan
    java.lang.ArrayIndexOutOfBoundsException
    at oracle.sql.NUMBER.toString(NUMBER.java:824)
    at oracle.jdbc.driver.OracleStatement.getStringValue(OracleStatement.java:3482)
    at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:434)
    at isidenet.it.sar.Query.eseguiSQLC2(Query.java:87)
    at isidenet.it.sar.Query.main(Query.java:282)
    Exception in thread "main"

    Hi My Friends here I am first please solve my problem
    The Program on JSP ,MS Access
    <%
    String dept_name=request.getParameter("D1");
    String itmp,itmcd,sn;
    %>
    <%
    Connection con;
    PreparedStatement ps;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:acc");
    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery("select * from item_details where Item_Name='"+dept_name+"'
    %>
    <div align="left">
    <table border="0" width="100%" height="400" >
    <td><font color="e8e800" size="4" face="arial unicode ms">Product name</td>
    <td><font color="#ffffff" size="4" face="arial unicode ms">Product description</td>
    <td><font color="#ffffff" size="4" face="arial unicode ms">Product code</td>
    <td><font color="#cc6600" size="4" face="arial unicode ms">Product price</td></tr>
    <form method=post action="mycreate.jsp">
    <%
    while(rs.next())
    %><tr>
    <td><font color="#ffffff" size="3" face="arial unicode
    ms">    <%=rs.getString(1)%></td>
    <td><font color="#ffffff" size="3" face="arial unicode
    ms">    <%=rs.getString(4)%></td>
    <td><font color="#ffffff" size="3" face="arial unicode
    ms">    <%=rs.getString(3)%></td>
    <% String temp=rs.getString(3);%>
    <%=temp%>
    <td><font color="#ffffff" size="3" face="arial unicode
    ms">    <%=rs.getString(5)%></td>
    <td><input type=submit value="Add to cart"></td></tr>
    <form method=post action="mycreate.jsp">
    <%
    con.close();
    %>
    </tr>
    </table></tr></table></tr></table>
    </form>
    </form>
    I have facing a problem on followed line:
    <%=rs.getString(3)%></td>
    <% String temp=rs.getString(3);%>
    <%=temp%>
    I want the value by fetching into a variable but I can't

  • How to print Integrity sql in the preparedstatement?

    How to print Integrity sql in the preparedstatement?
    Connection conn = null;
    String sql = "select * from person where name=?";
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setObject(1, "robin");
    ps.executeQuery();
    i'm wants print Integrity sql.
    For example:select * from person where name='robin'
    How should I do?
    thanks a lot!

    PreparedStatement doesn't offer methods for that. You can write your own implementation of PreparedStatement which wraps the originating PreparedStatement and saves the set* values and writes it to the toString().
    If needed, myself I just print the sql as well as the values-being-set to the debug statement.Logger.debug(query + " " + values);

  • PreparedStatement not working

    Hi,
    I am having some problem using PreparedStatement.executeUpdate() . I want to be able to prepare several queries before commiting and I wrote this just to test it
    PreparedStatement stmt= aConnection.prepareStatement("update trans_test1 set field1='a text field' where field1='other text'");
              stmt.executeUpdate();
              aConnection.commit();
              stmt.close();
              aConnection.close();
    when it hits this line "stmt.executeUpdate();" the program just stops running and after a while throws this error.
    java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
    I set the auto commit to false but I still can't get it working and do not understand the problem. Any one can help?
    Thanks so much
    Alejo

    Hi,
    I am having some problem using
    PreparedStatement.executeUpdate() . I want to be able
    to prepare several queries before commiting and I
    wrote this just to test it
    PreparedStatement stmt=
    aConnection.prepareStatement("update trans_test1 set
    field1='a text field' where field1='other text'");
              stmt.executeUpdate();This is wrong in so many ways:
    (1) Use the bind variables.
    (2) Close resources properly in a finally block.
    (3) You don't show where you set auto commit to false
    (4) You don't show where you rollback in the event of a failure.
    >
    I set the auto commit to false but I still can't get
    it working and do not understand the problem. Any one
    can help?A snippet like this isn't enough. Post all the code.
    Which database are you using, and which driver?
    %

  • Oracle, SELECT IN and PreparedStatement.setArray

    I want to execute the following query: SELECT * FROM SOMETABLE WHERE IDFIELD IN (?)
    The number of values in the IN list is variable. How can I do this with a prepared statement?
    I am aware of the different alternatives:
    1) Keep a cache of prepared statement for each sized list seen so far.
    2) Keep a cache of prepared statements for different sizes (1, 5, 10, 20) and fill in the left over parameter positions with the copies first value.
    They both have the disadvantage that there could be many prepared statements for each query that get used once, and never used again.
    I have tried this:
    stmt.execute ("CREATE OR REPLACE TYPE LONGINTLIST AS TABLE OF NUMBER(15)");
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor ("LONGINTLIST", conn);
    long idValues [] = {2, 3, 4};
    oracle.sql.ARRAY paramArray = new oracle.sql.ARRAY (desc, conn, idValues);
    PreparedStatement query = conn.prepareStatement ("SELECT * FROM MYTABLE WHERE ID_FIELD IN (?)");
    query.setArray (1, paramArray);
    But Oracle gives a data conversion error.
    I then tried this:
    PreparedStatement query = conn.prepareStatement ("SELECT * FROM MYTABLE WHERE ID_FIELD IN (SELECT * FROM TABLE (?))");
    This works and the rows are returned, but the Oracle optimizer does not like it very much, since it always does a full table scan even though there is a primary key index on ID_FIELD.
    Any ideas?
    I also tried this:
    OraclePreparedStatement oraQuery = (OraclePreparedStatement) query;
    oraQuery.setARRAY (1, paramArray);
    But same behavior.
    Roger Hernandez

    Please re-read the original message. As I mentioned,
    I am aware of the two commonly used alternatives.No actually the most used alternative is to build the SQL dynamically each time.
    I know how to get both of them to work, and have used
    both alternatives in the past. The downside to both
    these approaches is that you need to save multiple
    prepared statements for each query. What I am trying
    to find is a way of having only one saved prepared
    statement for a query having a variable number of IN
    clause parameters.You could probably use a stored procedure that takes an 'array' and then do the processing in the stored proc to handle each array element.
    However, your database might not support that stored procs or arrays. Or it might not cache it with arrays. And the overhead of creating the array structure or processing it in the proc might eat any savings that you might gain (even presuming there is any savings) by using a prepared statement in the first place. Of course given that you must be using an automated profiling tool and have a loaded test environment you should be able to easily determine if this method saves time or not.
    Other than that there are no other solutions.

  • OID can not display some users - java.lang.ArrayIndexOutOfBoundsException:0

    We have set up AD to OID synchronization for users and groups using Import connector, and it worked fine. The users in OID can log into applications protected by OAM. But recently I found that some users that could be displayed in OID before can not be displayed now. If I click on the DN in Oracle Directory Manager, a error window pops up. It is a long error message, and the first a few lines are as follows :
    0
    java.lang.ArrayIndexOutOfBoundsException:0
    at oracle.ldap.admin.AttrOptions.<init>(entry.jave:3151)
    at Oracle.ldap.admin.Entry.getProp(entry.java:457)
    I don't see any error message in the integration profile or log files. I am testing things on an account that is having this trouble, and the strange thing is that it can not log into application protected by OAM any more, but it can log into OAM console.
    We use OID 10.1.2.3 on Windows, and OAM 10.1.4.0.1.
    I searched in Metalink but didn't find anything helpful. Any help is appreciated. Thanks for your time.
    Hailie

    Pramod,
    Thank you for your reply. Please see below my answers to your questions:
    -> Do you see any pattern in the users (DN) that are unable to be displayed/login?
    Yes I do see some pattern. There is one change on the problem user's dn - the "\" after the last name is gone.
    Before: cn=smith\, john, cn=users,dc=abc,dc=com
    Now: cn=smith, john, cn=users,dc=abc,dc=com
    However I check in Active directory "\" is presented. In OID if I right click on cn=smith, john and try to delete it, I got a error message "LDAP: error code 34 - Error in DN Normalization". Is that caused by the missing of "\"?
    -> Does ldapsearch on these users (with all attributes) show something (special chars, etc)?
    ldapsearch on cn=cn=smith, john,cn=users,dc=abc,dc=com returns no objects:
    $ldapsearch -L -D "cn=orcladmin" -w "*****" -h host -p 389 -b "cn=smith, john,cn=users,dc=abc,dc=com" -s sub "objectclass=*"
    ldap_search: No such object
    ldap_search: matched: cn=Users, dc=abc,dc=com
    Ldap search on cn=smith\, john,cn=users,dc=abc,dc=com:
    $ldapsearch -L -D "cn=orcladmin" -w "*****" -h host -p 389 -b "cn=smith\, john,cn=users,dc=abc,dc=com" -s sub "objectclass=*"
    dn: cn="smith, john",cn=users,dc=abc,dc=com
    uid: [email protected]
    employeenumber: 916963
    cn: smith, john
    registeredaddress: 512
    krbprincipalname: [email protected]
    orclsamaccountname: ABC.COM$JSmith
    sn: johnsmith
    displayname: John
    orclobjectguid: lJO0N+8H4UW/30yHukSfsw==
    orclobjectsid: AQUAAAAAAAUVAAAAohxTYWIV3XFeP55cYjwAAA==
    orcluserprincipalname: [email protected]
    objectclass: oblixorgperson
    objectclass: inetorgperson
    objectclass: orcluserv2
    objectclass: person
    objectclass: orcladuser
    objectclass: organizationalPerson
    objectclass: top
    obver: 10.1.4.0
    -> Do you see the same behavior when you use any generic LDAP browser (Ex: Apache Directory Studio) instead of ODM?
    I don't have Apache Directory Studio installed yet. I will try that later.
    -> Does the changelog for the particular synch (for the affected users) show something?
    Here is what I found in ActiveChgImp.aud
    (weeks ago)
    97426524 : Success : MODIFY : cn=smith\, john,cn=users,dc=abc,dc=com
    (Recently change - The back slach after smith was gone, and "" showed up)
    97469970 : Success : MODIFY : cn="smith, john",cn=users,dc=abc,dc=com
    -> If login to OAM is possible, can the user modify his/her profile, and does it save the changes? If it does, can you try logging in to apps?
    This user can log into OAM identity system, but when I click on "My profile" under "User manager", I got a error message "You do not have sufficient access rights".
    If I log into identity system as orcladmin, I was able to modify it and save the changes. But in OID the user is still not displayed. Same error message. When I tried to add it as administrator, I could search on it, add it, but when I press "done", it didn't show up on the admin list. The users that can be displayed in OID can be added to admin list without a problem.
    Thanks,
    Hailie

  • Problem with PreparedStatement

    I'm using a statement which needs to determine if the value is in a group.
    The statement will be
    "select name,age,occupation from personnel where age in ?"
    ps.setString(1, "(20,21,22)");
    I've also tried
    ps.setString(1, "('20','21','22')");
    Neither brings back any values in the result set.
    I can't figure out how to print what the preparedstatement looks like after setting the value.
    I look in the table and there are records with age 20, 21, 22.. and age is set as a string.

    Try this:
        query_B = "select tablename.blah_blah_blah"
                + "  from tablename"
                + " where tablename.etc is null"
                + "   and table.blah_term_code       in (?, ?)"
                + " order by 1, 2, 4, 7";
          String[] in_sem_dt = { "200307", "200308" };
          pstmt_B = con.prepareStatement( query_B );
          pstmt_B.setString( 1, in_sem_dt[0] );
          pstmt_B.setString( 2, in_sem_dt[1] );
          rs_B = pstmt_B.executeQuery();~Bill

  • Closing PreparedStatements & ResultSets

    Is it necessary to explicitly close ResultSet AND PreparedStatement objects when used together? For example:
    PreparedStatement ps;
    ResultSet rs;
    String sql = " SELECT * FROM some_table WHERE id = ? ";
    try {
        ps = connection.prepareStatement(sql);
        ps.setString(1, someId);
        rs = ps.executeQuery();
        // And so on.....
    } finally {
      rs.close();
      ps.close();
    }Is it sufficient to close only the PreparedStatement? Does the ResultSet get cleaned up automatically when the PreparedStatement is closed? I don't want any lingering cursors left open, but at the same time, I don't want to write code that isn't needed. What's considered best form?
    Thanks.
    BTW: I'm using Oracle 8i/9i.

    I always close a Statement object, but don't worry about the ResultSet...that's really just a matter of redundancy...
    From the API on Statement.close()
    Note: A Statement object is automatically closed when it is garbage collected. When a Statement object is closed, its current ResultSet object, if one exists, is also closed.

  • Too many connections - even after closing ResultSets and PreparedStatements

    I'm getting a "Too many connections" error with MySQL when I run my Java program.
    2007-08-06 15:07:26,650 main/CLIRuntime [FATAL]: Too many connections
    com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Too many connections
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:921)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:812)
            at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3269)
            at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1182)
            at com.mysql.jdbc.Connection.createNewIO(Connection.java:2670)I researched on this and found out that I wasn't closing the ResultSet and the PreparedStatement.
    The JDBC connection is closed by a central program that handles connections (custom connection pooling).
    I added the code to close all ResultSets and PreparedStatements, and re-started MySQL as per the instructions here
    but still get "Too many connections" error.
    A few other things come to mind, as to what I may be doing wrong, so I have a few questions:
    1) A few PreparedStatements are created in one method, and they are used in a 2nd method and closed in the 2nd method
    does this cause "Too many connections" error?
    2) I have 2 different ResultSets, in nested while loops where the outer loop iterates over the first ResultSet and
    the inner loop iterates over the second ResultSet.
    I have a try-finally block that wraps the inner while loop, and I'm closing the second ResultSet and PreparedStement
    in the inner while loop.
    I also have a try-finally block that wraps the outer while loop, and I'm closing the first ResulSet and PreparedStatement
    in the outer while loop as soon as the inner while loop completes.
    So, in the above case the outer while loop's ResultSet and PreparedStatements remain open until the inner while loop completes.
    Does the above cause "Too many connections" error?
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The following is relevant sections of my code ( it is partially pseudo-code ) that shows the above 2 cases:
    init( Connection jdbcConnection ){
       String firstSQLStatement = "....";
       PreparedStatement ps1 = jdbcConnection.prepareStatement( firstSQLStatement );
       String secondSQLStatement = "....";
       PreparedStatement ps2 = jdbcConnection.prepareStatement( secondSQLStatement );
       String thirdSQLStatement = "....";
       PreparedStatement ps3 = null;
       ResultSet rsA = null;
       try{
            ps3 = jdbcConnection.prepareStatement( thirdSQLStatement );
            rsA = ps3.executeQuery();
            if( rsA.next() ){
                   rsA.getString( 1 );
       }finally{
            if( rsA != null )
                   rsA.close();
            if( ps3 != null )
              ps3.close();
       //Notice, how ps1 and ps2 are created here but not used immediately, but only ps3 is
       //used immediately.
       //ps1 and ps2 are used in another method.
    run( Connection jdbcConnection ){
         ResultSet rs1 = ps1.executeQuery();
            try{
               while(rs1.next()){
                    String s = rs1.getString();
                    ps2.setString(1, s);
              ResultSet rs2 = ps2.executeQuery();
                    try{
                   while(rs2.next()){
                        String s2 = rs2.getString();
                    }finally{
                   if( rs2 != null )
                     rs2.close();
                   if( ps2 != null )
                     ps2.close();
         }catch( Exception e ){
              e.printStackTrace();
         }finally{
            if( rs1 != null )
                  rs1.close();
               if( ps1 != null )
                  ps1.close();
    //Notice in the above case rs1 and ps1 are closed only after the inner
    //while loop completes.
    }I appreciate any help.

    Thanks for your reply.
    I will look at the central connection pooling mechanism ( which was written by someone else) , but that is being used by many other Java programs others have written.
    They are not getting this error.
    An addendum to my previous note, I followed the instructions here.
    http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html
    There's probably something else in my code that is not closing the connection.
    But I just wanted to rule out the fact that opening a PreparedStatement in one method and closing it in another is not a problem.
    Or, if nested ResultSet loops don't cause the problem.
    I've read in a few threads taht "Too many connections" can occur for unclosed RS and PS , and not just JDBC connections.

  • Memory problems with PreparedStatements

    Driver: 9.0.1 JDBC Thin
    I am having memory problems using "PreparedStatement" via jdbc.
    After profiling our application, we found that a large number oracle.jdbc.ttc7.TTCItem objects were being created, but not released, even though we were "closing" the ResultSets of a prepared statements.
    Tracing through the application, it appears that most of these TTCItem objects are created when the statement is executed (not when prepared), therefore I would have assumed that they would be released when the ResultSet is close, but this does not seem to be the case.
    We tend to have a large number of PreparedStatement objects in use (over 100, most with closed ResultSets) and find that our application is using huge amounts of memory when compared to using the same code, but closing the PreparedStatement at the same time as closing the ResultSet.
    Has anyone else found similar problems? If so, does anyone have a work-around or know if this is something that Oracle is looking at fixing?
    Thanks
    Bruce Crosgrove

    From your mail, it is not very clear:
    a) whether your session is an HTTPSession or an application defined
    session.
    b) What is meant by saying: JSP/Servlet is growing.
    However, some pointers:
    a) Are there any timeouts associated with session.
    b) Try to profile your code to see what is causing the memory leak.
    c) Are there references to stale data in your application code.
    Marilla Bax wrote:
    hi,
    we have some memory - problems with the WebLogic Application Server
    4.5.1 on Sun Solaris
    In our Customer Projects we are working with EJB's. for each customer
    transaction we create a session to the weblogic application server.
    now there are some urgent problems with the java process on the server.
    for each session there were allocated 200 - 500 kb memory, within a day
    the JSP process on our server is growing for each session and don't
    reallocate the reserved memory for the old session. as a work around we
    now restart the server every night.
    How can we solve this problem ?? Is it a problem with the operating
    system or the application server or the EJB's ?? Do you have problems
    like this before ?
    greetings from germany,

  • PreparedStatement ResultSet wrapper to auto close cursor

    Hi !
    Is it possible to create wrapper that will automatically close result set and prepared statements ?
    I am sick of closing resultsets and preparedstatements in all my dao objects. Its all about neverending try catch and close code lines, it is all against the java garbage collector idea.
    Do you have any workaround ? Or I need to use with those try catch and close.
    Thanks !

    when u allocate object u dont need to call free nor destory when u dont need the object anymore.
    on the other hand, you need to call .close() when u dont need the prepared statement anymore

Maybe you are looking for

  • Block step in BPM

    Hi Experts,   I am facing a problem in BPM, 1) Receive the Message 2) Split the Message 3) Block starts     a) Synchronous send to RFC     b)Response from this is send to Send step In this scenario, the Message is going upto "BLOCK" step, and from th

  • Ability to save graphic settings on dataview across all users

    Hello All, Do you know how to save a graphic setting on a dataview? i.e. i have customized a graph on my dataview, which have specific settings. When i go into the dataview, my settings are as per defined. however when another user enters the datavie

  • Video 100% Audio 0%

    I've an interesting problem. I can do audio chat with no problem at all. When I try a video chat I get pictures at both ends but no audio. Looking at the Connection Doctor shows a 0% Audio quality. Both ends have 2Mbps DSL with 384 Kbps upload speed.

  • How to create Quotation from Ad hoc cost estimation of cProjects?

    Hi Guruu2019s Please help me in resolving the issue given below. I am able to get ad hoc cost estimation results in accounting screen, but not able to create a Quotation from Ad hoc cost estimation of cProjects. I am here with providing necessary ste

  • How to delete massive amounts of email on iPhone

    Hi. I have over 1500 emails in an earthlink.net email account on an iPhone running iOS 8.1 and want to mass-delete all but the last 3 months - say 120 emails. Is there a way to do this other than one-by-one manually?