ORA-01008: not all variables bound error in WebLOgic connection pooling

ORA-01008: not all variables bound error in WebLOgic connection pooling

Post by Roger Chung-We » Mon, 12 Aug 2002 21:05:44



I am getting "ORA-01008: not all variables bound" when using the
prepareStatement method when connected via connection pooling with an
OCI driver, but it works when using a direct connection with a thin
ORACLE JDBC driver (classes12.zip). This failure is on both NT and
Solaris 2.6.

Here's the relevant code snippets:
public static Connection conn;
...
Context myCtx = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)myCtx.lookup("Keown");
conn = ds.getConnection();
...
PreparedStatement myPs = null;
String myAgmntSQL = "select start_dt, end_dt " +
"from sma_agmnts " +
"where agmnt_sys_id = ?";
myPs = myConnect.conn.prepareStatement(myAgmntSQL);

If I hardcode a value like 767 instead of ?, there is no error.

I believe that the error is occurring in the prepareStatement method
as I've inserted system outs before and after it to pin down where it
was failing.

The weblogic.properties file contains this:

weblogic.jdbc.connectionPool.banana=\
url=jdbc:weblogic:oracle,\
driver=weblogic.jdbc.oci.Driver,\
loginDelaySecs=1,\
initialCapacity=1,\
maxCapacity=10,\
capacityIncrement=2,\
allowShrinking=true,\
shrinkPeriodMins=15,\
refreshMinutes=10,\
testTable=dual,\
props=user=pcm8744;password=password;server=dldv
weblogic.allow.reserve.weblogic.jdbc.connectionPool.banana=ba,guest

# Data Source definition for banana
weblogic.jdbc.DataSource.Keown=banana
--
Visit Caribbean Aviation:
http://www.caribbeanaviation.com/

 
 
 

ORA-01008: not all variables bound error in WebLOgic connection pooling

Post by AV » Mon, 12 Aug 2002 23:44:53


It can be if you do not call any setter for "?"
and call execute().
Please, post several more lines of code and
try to identify exact place where exception is thrown.

AlexV.


Quote:> I am getting "ORA-01008: not all variables bound" when using the
> prepareStatement method when connected via connection pooling with an
> OCI driver, but it works when using a direct connection with a thin
> ORACLE JDBC driver (classes12.zip). This failure is on both NT and
> Solaris 2.6.

> Here's the relevant code snippets:
> public static Connection conn;
> ...
> Context myCtx = new InitialContext();
> javax.sql.DataSource ds = (javax.sql.DataSource)myCtx.lookup("Keown");
> conn = ds.getConnection();
> ...
> PreparedStatement myPs = null;
> String myAgmntSQL = "select start_dt, end_dt " +
> "from sma_agmnts " +
> "where agmnt_sys_id = ?";
> myPs = myConnect.conn.prepareStatement(myAgmntSQL);

> If I hardcode a value like 767 instead of ?, there is no error.

> I believe that the error is occurring in the prepareStatement method
> as I've inserted system outs before and after it to pin down where it
> was failing.

> The weblogic.properties file contains this:

> weblogic.jdbc.connectionPool.banana=\
> url=jdbc:weblogic:oracle,\
> driver=weblogic.jdbc.oci.Driver,\
> loginDelaySecs=1,\
> initialCapacity=1,\
> maxCapacity=10,\
> capacityIncrement=2,\
> allowShrinking=true,\
> shrinkPeriodMins=15,\
> refreshMinutes=10,\
> testTable=dual,\
> props=user=pcm8744;password=password;server=dldv
> weblogic.allow.reserve.weblogic.jdbc.connectionPool.banana=ba,guest

> # Data Source definition for banana
> weblogic.jdbc.DataSource.Keown=banana
> --
> Visit Caribbean Aviation:
> http://www.caribbeanaviation.com/


 
 
 

ORA-01008: not all variables bound error in WebLOgic connection pooling

Post by Roger Chung-We » Fri, 16 Aug 2002 04:28:52




Quote:>It can be if you do not call any setter for "?"
>and call execute().
>Please, post several more lines of code and
>try to identify exact place where exception is thrown.

I knocked up a small JSP page to demonstate this. The last part of the
log, including the stack trace, follows the program listing.

As you can see from the log, the program apears to fail on this:

 myPs = conn.prepareStatement(myAgmntSQL);

I'm baffled by the "ORA-01008: not all variables bound" error message
because I'm binding the variable by using setString method, and this
works when doing a direct connection to ORACLE with the thin JDBC
driver.

The variable is defined in the database as NUMBER. I've experimented
with setString and setLong, but to no avail.

I've scoured the web sites and newsgroups, but nobody who has had a
similar problem seems to have had a resolution. None of the Java guys
in my office can help either.

Roger.

************start of JSP page***************

language="java"
import="java.sql.Connection, java.sql.SQLException,
java.sql.PreparedStatement, java.sql.ResultSet, javax.naming.Context,
javax.naming.InitialContext,
 javax.sql.DataSource, javax.naming.NamingException,
java.io.StringWriter, java.lang.Long"
session="true"
buffer="8kb"
autoFlush="true"
isThreadSafe="true"
isErrorPage="false"
contentType="text/html; charset=ISO-8859-1"
%>
<html>
<body>
<p>
Test to show connection pooling connectionto DB
</p>
<%
String myAgmntStartDate = null;
String myAgmntEndDate = null;
Connection conn = null;
PreparedStatement myPs = null;
ResultSet myRs = null;

String myAgmntSQL = "select start_dt, end_dt " +
                    "from sma_agmnts " +
                    "where agmnt_sys_id = ?";
String myAgmntSysId = "767";
//long myAgmntSysIdLong = Long.parseLong(myAgmntSysId.trim());
try
{
    Context myCtx = new InitialContext();
    System.out.println("Created Context");

    DataSource ds = (DataSource)myCtx.lookup("Keown");
    System.out.println("Keown has a big datasource");

    conn = ds.getConnection();

    System.out.println("About to call prepareStatement");
    myPs = conn.prepareStatement(myAgmntSQL);
    System.out.println("About to call setString");
    myPs.setString(1,myAgmntSysId);
//    myPs.setLong(1,myAgmntSysIdLong);
    System.out.println("About to call executeQuery");
    myRs = myPs.executeQuery();
    if (myRs.next())
    {
        System.out.println("Obtaining agreement start/end dates for "
+ myAgmntSysId);
        myAgmntStartDate = myRs.getString(1);
        myAgmntEndDate = myRs.getString(2);
        System.out.println("Start date: " + myAgmntStartDate);
        System.out.println("End date: " + myAgmntEndDate);
    }

Quote:}

catch(SQLException sqle)
{
    System.out.println("Error on getting datasource connection: " +
sqle.getMessage());
    StringWriter mySw = new StringWriter();
    sqle.printStackTrace(new PrintWriter(mySw));
    String myTrace = mySw.toString();
    System.out.println(myTrace);
Quote:}

catch (NamingException ne)
{
  System.out.println("Error in retrieving Keown: " +
ne.getExplanation());
Quote:}

catch (Exception e)
{
  System.out.println("Keown is ugly: " + e.getMessage());
Quote:}

finally
{
    try
    {
        if (myRs != null)
        {
            myRs.close();
        }
        if (myPs != null)
        {
            myPs.close();
        }
    }
    catch (SQLException sqle)
    {
        System.out.println("Error in close: " + sqle.getMessage());
    }
Quote:}

%>
</body>
</html>

***********LOG********************

Wed Aug 14 08:49:02 GMT+00:00 2002:<I> <ServletContext-General>
Generated
java file:
/be/home/bedev02/weblogic/myserver/classfiles/jsp_servlet/_sma/_Test2.java
Created Context
Keown has a big datasource
About to call prepareStatement
Error on getting datasource connection: ORA-01008: not all variables
bound
java.sql.SQLException: ORA-01008: not all variables bound
        at
weblogic.db.oci.OciCursor.getCDAException(OciCursor.java:228)
        at
weblogic.jdbcbase.oci.Statement.private_parse(Statement.java:717)
        at
weblogic.jdbc.oci.Connection.prepareStatement(Connection.java:42)
        at
weblogic.jdbc20.pool.Connection.prepareStatement(Connection.java:45)
        at
weblogic.jdbc20.rmi.internal.ConnectionImpl.prepareStatement(ConnectionImpl.java:80)

        at
weblogic.jdbc20.rmi.SerialConnection.prepareStatement(SerialConnection.java:55)

        at jsp_servlet._sma._Test2._jspService(_Test2.java:123)
        at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
        at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:105)
        at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:123)
        at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:742)
        at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:686)
        at
weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:247)
        at
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)
        at
weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
        at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

 
 
 

ORA-01008: not all variables bound error in WebLOgic connection pooling

Post by AV » Fri, 16 Aug 2002 05:45:15


<oradocs>
ORA-01008 not all variables bound

Cause: A SQL statement containing substitution variables was executed
without all variables bound. All substitution variables must have a
substituted value before the SQL statement is executed.

Action: In OCI, use an OBIND or OBINDN call to substitute the required
values.

</oradocs>

Looks like a driver bug : something like premature
call to execute.

I suggest the following:

-- for convenience, do all debugging in separate java class, not in jsp.
-- switch to THIN driver from OCI
-- try Oracle-specific syntax's: instead of "?" try ":1", ":2" and so on
-- ask weblogic people (for example, Joe Weinstein) for help.
-- check compatibility of server, driver and database

AlexV.




> >It can be if you do not call any setter for "?"
> >and call execute().
> >Please, post several more lines of code and
> >try to identify exact place where exception is thrown.

> I knocked up a small JSP page to demonstate this. The last part of the
> log, including the stack trace, follows the program listing.

> As you can see from the log, the program apears to fail on this:

>  myPs = conn.prepareStatement(myAgmntSQL);

> I'm baffled by the "ORA-01008: not all variables bound" error message
> because I'm binding the variable by using setString method, and this
> works when doing a direct connection to ORACLE with the thin JDBC
> driver.

> The variable is defined in the database as NUMBER. I've experimented
> with setString and setLong, but to no avail.

> I've scoured the web sites and newsgroups, but nobody who has had a
> similar problem seems to have had a resolution. None of the Java guys
> in my office can help either.

> Roger.

> ************start of JSP page***************

> language="java"
> import="java.sql.Connection, java.sql.SQLException,
> java.sql.PreparedStatement, java.sql.ResultSet, javax.naming.Context,
> javax.naming.InitialContext,
>  javax.sql.DataSource, javax.naming.NamingException,
> java.io.StringWriter, java.lang.Long"
> session="true"
> buffer="8kb"
> autoFlush="true"
> isThreadSafe="true"
> isErrorPage="false"
> contentType="text/html; charset=ISO-8859-1"
> %>
> <html>
> <body>
> <p>
> Test to show connection pooling connectionto DB
> </p>
> <%
> String myAgmntStartDate = null;
> String myAgmntEndDate = null;
> Connection conn = null;
> PreparedStatement myPs = null;
> ResultSet myRs = null;

> String myAgmntSQL = "select start_dt, end_dt " +
>                     "from sma_agmnts " +
>                     "where agmnt_sys_id = ?";
> String myAgmntSysId = "767";
> //long myAgmntSysIdLong = Long.parseLong(myAgmntSysId.trim());
> try
> {
>     Context myCtx = new InitialContext();
>     System.out.println("Created Context");

>     DataSource ds = (DataSource)myCtx.lookup("Keown");
>     System.out.println("Keown has a big datasource");

>     conn = ds.getConnection();

>     System.out.println("About to call prepareStatement");
>     myPs = conn.prepareStatement(myAgmntSQL);
>     System.out.println("About to call setString");
>     myPs.setString(1,myAgmntSysId);
> //    myPs.setLong(1,myAgmntSysIdLong);
>     System.out.println("About to call executeQuery");
>     myRs = myPs.executeQuery();
>     if (myRs.next())
>     {
>         System.out.println("Obtaining agreement start/end dates for "
> + myAgmntSysId);
>         myAgmntStartDate = myRs.getString(1);
>         myAgmntEndDate = myRs.getString(2);
>         System.out.println("Start date: " + myAgmntStartDate);
>         System.out.println("End date: " + myAgmntEndDate);
>     }

> }

> catch(SQLException sqle)
> {
>     System.out.println("Error on getting datasource connection: " +
> sqle.getMessage());
>     StringWriter mySw = new StringWriter();
>     sqle.printStackTrace(new PrintWriter(mySw));
>     String myTrace = mySw.toString();
>     System.out.println(myTrace);
> }
> catch (NamingException ne)
> {
>   System.out.println("Error in retrieving Keown: " +
> ne.getExplanation());
> }
> catch (Exception e)
> {
>   System.out.println("Keown is ugly: " + e.getMessage());
> }
> finally
> {
>     try
>     {
>         if (myRs != null)
>         {
>             myRs.close();
>         }
>         if (myPs != null)
>         {
>             myPs.close();
>         }
>     }
>     catch (SQLException sqle)
>     {
>         System.out.println("Error in close: " + sqle.getMessage());
>     }
> }
> %>
> </body>
> </html>

> ***********LOG********************

> Wed Aug 14 08:49:02 GMT+00:00 2002:<I> <ServletContext-General>
> Generated
> java file:
> /be/home/bedev02/weblogic/myserver/classfiles/jsp_servlet/_sma/_Test2.java
> Created Context
> Keown has a big datasource
> About to call prepareStatement
> Error on getting datasource connection: ORA-01008: not all variables
> bound
> java.sql.SQLException: ORA-01008: not all variables bound
>         at
> weblogic.db.oci.OciCursor.getCDAException(OciCursor.java:228)
>         at
> weblogic.jdbcbase.oci.Statement.private_parse(Statement.java:717)
>         at
> weblogic.jdbc.oci.Connection.prepareStatement(Connection.java:42)
>         at
> weblogic.jdbc20.pool.Connection.prepareStatement(Connection.java:45)
>         at

weblogic.jdbc20.rmi.internal.ConnectionImpl.prepareStatement(ConnectionImpl.
java:80)
Quote:

>         at

weblogic.jdbc20.rmi.SerialConnection.prepareStatement(SerialConnection.java:
55)
Quote:

>         at jsp_servlet._sma._Test2._jspService(_Test2.java:123)
>         at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
>         at

weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:105)
Quote:>         at

weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:123)
Quote:>         at

weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
l.java:742)
Quote:>         at

weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
l.java:686)
Quote:>         at

weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
Manager.java:247)
Quote:>         at

weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)

- Show quoted text -

Quote:>         at
> weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
>         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)