Ingres prepared statement error

Hi there,
I 'm encountering a very strange problem with a prepared statement and ingres.
String strSQL = "select first 50 date_part('year', dtrans_date) as year, ccalled_place as place, "  +
"count(*) as calls, " +
"sum(nduration/60.0) as duration " +
"from phone " +
"where date_part('year', dtrans_date) = ? and cDest_type='C' " +
"group by date_part('year', dtrans_date), ccalled_place " +
"order by date_part('year', dtrans_date), calls desc";
PreparedStatement ps = conn.prepareStatement(strSQL);          
ps.setInt(1, 2000);
rs = ps.executeQuery();It throws the exception:
ca.gcf.util.SqlEx: An internal error prevents further processing of this query.
Associated error messages which provide more detailed information about the problem can be found in the error log, II_CONFIG:errlog.log
     at ca.gcf.jdbc.DrvObj.readError(DrvObj.java:773)
     at ca.gcf.jdbc.DrvObj.readResults(DrvObj.java:629)
     at ca.gcf.jdbc.DrvPrep.<init>(DrvPrep.java:137)
     at ca.gcf.jdbc.DrvConn.getPrepStmt(DrvConn.java:786)
     at ca.gcf.jdbc.JdbcPrep.<init>(JdbcPrep.java:364)
     at ca.gcf.jdbc.JdbcConn.createPrep(JdbcConn.java:1550)
     at ca.gcf.jdbc.JdbcConn.prepareStatement(JdbcConn.java:1380)
     at TestIngresDB.query(TestIngresDB.java:37)
     at TestIngresDB.<init>(TestIngresDB.java:9)
     at TestIngresDB.main(TestIngresDB.java:55)This is exactly at the line:
ps = conn.prepareStatement(strSQL);Checking Ingres' error log:
FREEFALL: 32867             , 12f678e0]: Thu Dec  2 07:01:57 2004 E_SC0207_UNEXPECTED_ERROR    Facility returned an undocumented error.
FREEFALL: 32867             , 12f678e0]: ULE_FORMAT: Couldn't look up message 0 (reason: ER error 10902)
E_CL0902_ER_NOT_FOUND   No text found for message identifier
FREEFALL: 32867             , 12f678e0]: Thu Dec  2 07:01:57 2004 E_SC0215_PSF_ERROR   Error reHowever, other prepared statements like this work fine, e.g.:
String sqlStr = "SELECT * FROM Stock WHERE Item_Number = ?";
PreparedStatement pstmt = con.prepareStatement(query);
pstmt.setInt(1, 2);
ResultSet rs = pstmt.executeQuery();Sorry if this posting is not appropriate here, but I really don't know if this has something to do with JDBC or Ingres driver itself. Note that the query runs perfectly ok when run from Ingres VisualDBA.
Thanks,
John.

Your prepared statement looks like
select first 50 date_part('year', dtrans_date) as year, ccalled_place as place, count(*) as calls, sum(nduration/60.0) as duration from phone where date_part('year', dtrans_date) = ? and cDest_type='C' group by date_part('year', dtrans_date), ccalled_place order by date_part('year', dtrans_date), calls desc
I am not sure what this "first 50" is for?
***Annie***

Similar Messages

  • Prepared statement error

    hello friends,
    iam using the following code when i tryo to compile it gives the error as follow
    <code>
    import java.sql.*;
    import java.util.*;
    class DbDemoPrepared
    public static void main (String args[]) throws SQLException
    Class.forName("com.mysql.jdbc.Driver");
    String url="jdbc.mysql://localhost:3306";
    java.util.Properties p=new java.util.Properties();
    p.put("user","ser");
    p.put("password","heslo");
    Connection conn=DriverManager.getConnection(url,p);
    PreparedStatement ps=conn.prepareStatement("Select * from emp where empno = ? ");
    ps.setInt(1,Integer.parseInt(args[0]));
    ResultSet rs=ps.executeQuery();
    ResultSetMetaData rm= rs.getMetaData();
    int cols=rm.getColumnCount();
    System.out.println();
    for (int i=0;i<=cols;i++)
    System.out.print(rm.getColumnName(i)+"\t");
    System.out.println();
    while(rs.next())
    for (int i=1;i<=cols;i++)
    System.out.print(rs.getString(i)+"\t");
    System.out.println();
    ps.close();
    conn.close();
    </code>
    [root@server jdbc]# javac DbDemoPrepared.java
    DbDemoPrepared.java:10: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown
    Class.forName("com.mysql.jdbc.Driver");
    ^
    1 error
    so how to proceed
    with regards
    rama kanth

    thanks for your reply
    but the driver class has been installed successfully there becuause
    the other programs are running perfectly with the same driver.Wrong.
    if at all we need to catch that exception i tried like this
    try{
    Class.forName("com.mysql.jdbc.Driver");
    catch (SQLException e)
    System.out.println("error"+e);
    }This is Java 101. If the method in the try block throws a checked Exception X, then you have to have to have a catch block that handles it. That's what the compiler is telling you.
    but its giveng the erroe like this
    [root@server jdbc]# javac DbDemoPrepared.java
    DbDemoPrepared.java:12: exception
    java.sql.SQLException is never thrown in body of
    corresponding try statement
    catch (SQLException e)
    ^
    DbDemoPrepared.java:10: unreported exception
    java.lang.ClassNotFoundException; must be caught or
    declared to be thrown
    Class.forName("com.mysql.jdbc.Driver");
    ^
    2 errorsWhy isn't the advice the compiler is giving you good enough?
    >
    >
    >
    with regards
    rama kath
    Better go back and re-read the intro Java tutorial.

  • Prepared statement error-reply soon please

    hi,i am using a preparedstatement ,i get an error that i am not able to figure out.please help.heres the code
    i have a table called fun with two fields
    String temp="fun"; //the table name will vary so its kept a variable
    String query="insert into"+temp+"values(?,?)";
    PreparedStatement samp=prepareStatement(query);
    samp.setInt(1,2);
    samp.setString(2,"adsd");
    samp.executeQuery();
    when i execute this it gives an SQL Exception
    missing INTO keyword.
    i have also tried it with executeUpdate().it gives the same error.what could be the problem.can i give the table name dynamically in some otherway.the same method works fine for create table but errors for insert statement.how can this be corrected.bye thiyagu.

    String query="insert into"+temp+"values(?,?)";This line is wrong because you have no space after the into or before values.
    This should work...
    String query="insert into " + temp + " values(?,?)";

  • Prepared Statement error, someone plz help

    strQuery = qryProvide.supplyNotReceivedQuery();
    logObject.log("CompDataProvider","supplyNotReceivedRecords",strQuery, XMLMON_Constants.LOG_DEBUG);
    stmtRestSchema = con.prepareStatement(strQuery);
    stmtRestSchema.setString(1,loadingPoint.trim());
    stmtRestSchema.setString(2,schemaName.trim());
    stmtRestSchema.setInt(3, process);
    stmtRestSchema.setString(4,strFromDt.trim());
    rsRestSchema = stmtRestSchema.executeQuery();
    if(rsRestSchema.next()){
         String proid = rsRestSchema.getString(XMLMON_Constants.MON_LOGS_PROCESS_ID);
         int refid = rsRestSchema.getInt(XMLMON_Constants.MON_LOGS_REFID);
    } else {
         String strQry = qryProvide.supplyNotRecQuery();
         logObject.log("CompDataProvider","supplyNotReceivedRecords",strQry, XMLMON_Constants.LOG_DEBUG);
         stmtData = con.prepareStatement(strQry.toString());
         stmtData.clearParameters();
         stmtData.setString(1, loadingPoint.trim());
         stmtData.setString(2, schemaName.trim());
         stmtData.setInt(3, process);
         stmtData.setString(4,strFromDt.trim());
         /***************** Its Reaching here/
         rsData = stmtData.executeQuery(strQuery);
         /***************** Its failing here throwing exception not all variables bound/
         if(!( rsData.next() ) ){
         //     do something here
         } else{
              System.out.println("do nothing");
         rsData.close();
         stmtData.close();
    rsRestSchema.close();
    stmtRestSchema.close();
    Can anyone help me in solving the error. i have found the error where and i m not able to find why. please i need help.

    Could you print out the query, e.g. strQry, I
    think the problem lies in the Query string.

  • JSP Deployment:Tomcat:Oracle Prepared Statement error

    I'm deploying my BC4J JSP application to Linux/Tomcat 4.0.1.
    The html and basic jsp (Query form display) work but whenever I try to hit the database (i.e. display a browse or execute a query), I get the following in the Browser window:
    Application Error
    Return
    Error Message: oracle.jdbc.driver.OraclePreparedStatement
    There are no other messages. Everything works in the JDeveloper IDE.
    I'm sure I've done something wrong in the configuration.
    Can anyone point me in the right direction?
    TIA
    Thanks, George

    Thanks for the info Sung.
    We solved the problem late yesterday. The Tomcat documentation indicates that .jar files shared by the application and the server must reside in <Tomcat_home>/common/lib/. However, we went by the JDeveloper document which stated that most of the library files belong in <Tomcat_home>/lib/.
    When we moved classes12.jar to /common/lib/ the problem was resolved.
    In order to resolve other problems that arose, we had to move all of the indicated .jar files for JDeveloper into /common/lib/.
    One of the JDeveloper documentation folks should probably evaluate this for a change to the documentation.
    Thanks for your help!
    Thanks, George

  • Weblogic 8.1 Oracle prepared statement error

    I've got WLS 8.1SP1 running on Mac OS X (10.2.6, JDK 1.4.1) using the Oracle Thin
    driver to connect to a 9.2.0.1 db on WinXP. When I run a unit test that uses
    an XA connection, I get the error below (inside a much larger stack trace). I'm
    not getting this error with 7.0SP2 (with Mac JDK 1.3.1). Is anyone familiar with
    what the code is trying to do here?
    [junit] --------------- nested within: ------------------
    [junit] weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Failed
    to generate class for weblogic.jdbc.rmi.internal.PreparedStatementImpl_weblogic_jdbc_wrapper_PreparedStatement_oracle_jdbc_driver_OraclePreparedStatement_811_WLStub
    ] - with nested exception:
    [junit] [java.lang.reflect.InvocationTargetException - with target exception:
        [junit] [java.lang.ArrayIndexOutOfBoundsException: 142]]
    [junit] at weblogic.rmi.internal.StubGenerator.generateStub(StubGenerator.java:807)
    [junit] at weblogic.rmi.internal.StubGenerator.generateStub(StubGenerator.java:790)
    [junit] at weblogic.rmi.extensions.StubFactory.getStub(StubFactory.java:79)
    [junit] at weblogic.rmi.utils.io.RemoteObjectReplacer.resolveObject(RemoteObjectReplacer.java:222)
    [junit] at weblogic.rmi.internal.StubInfo.readResolve(StubInfo.java:142)

    Craig,
    Normally AssertionError means that you hit the bug. Contact [email protected]
    for a resultion.
    Regards,
    Slava Imeshev
    <Craig Daniels cldanielsATcheckfree.com> wrote in message
    news:[email protected]..
    >
    I've got WLS 8.1SP1 running on Mac OS X (10.2.6, JDK 1.4.1) using theOracle Thin
    driver to connect to a 9.2.0.1 db on WinXP. When I run a unit test thatuses
    an XA connection, I get the error below (inside a much larger stacktrace). I'm
    not getting this error with 7.0SP2 (with Mac JDK 1.3.1). Is anyonefamiliar with
    what the code is trying to do here?
    [junit] --------------- nested within: ------------------
    [junit] weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[Failed
    to generate class forweblogic.jdbc.rmi.internal.PreparedStatementImpl_weblogic_jdbc_wrapper_Prepa
    redStatement_oracle_jdbc_driver_OraclePreparedStatement_811_WLStub
    ] - with nested exception:
    [junit] [java.lang.reflect.InvocationTargetException - with target
    exception:>     [junit [java.lang.ArrayIndexOutOfBoundsException: 142]]
    [junit] atweblogic.rmi.internal.StubGenerator.generateStub(StubGenerator.java:807)
    [junit] atweblogic.rmi.internal.StubGenerator.generateStub(StubGenerator.java:790)
    [junit] atweblogic.rmi.extensions.StubFactory.getStub(StubFactory.java:79)
    [junit] atweblogic.rmi.utils.io.RemoteObjectReplacer.resolveObject(RemoteObjectReplace
    r.java:222)
    [junit] atweblogic.rmi.internal.StubInfo.readResolve(StubInfo.java:142)

  • Error with ExecuteQuery() in prepared statement

    Hello,
    i' m a new one at java. I' m trying to build a web application in jsp and i have a problem in a simple at log in authentication.
    My code is this:
    <html>
    <head>
    <title>Welcome to the online Boat Shop, Inc.</title></head>
    <body>
    <%@ page language ="java" import = "java.io.*, java.lang.*, java.sql.*" %>
    <% try
    String strUsername = request.getParameter("USERNAME");
    String strPassword = request.getParameter("PASSWORD");
    Class.forName ("org.apache.derby.jdbc.ClientDriver");
    Connection myConn = DriverManager.getConnection("jdbc:derby://localhost:1527/boatsdb","tony", "logo");
    String strSQL = "SELECT USERNAME, PASSWORD FROM BOATDB where USERNAME = ? and PASSWORD = ?";
    PreparedStatement stmt = myConn.prepareStatement(strSQL);
    stmt.setString(1, "USERNAME");
    stmt.setString(2, "PASSWORD");
    ResultSet myResult = stmt.executeQuery(strSQL);
    if(myResult.next()){
    out.println("Login Succesful! A record with the given user name and password exists");
    } else {
    out.println("Login Failed. No records exists with the given user name and password");
    myResult.close();
    stmt.close();
    myConn.close();
    } catch(Exception e){
    out.println(e);
    %>
    </body>
    </html>
    The problem is that prepared statement doesn't support executeQuery() method and i can find any solution. The error is this:
    java.sql.SQLException: Method 'executeQuery(String)' not allowed on prepared statement. I already have some data in my database so that it can return results.
    Thank you.
    Edited by: antonis on May 3, 2008 6:13 AM

    thank you, that was the problem. It seems that i have also done mistakes in passing the username and password from the forms to the database for checking, because the message that i get always when i log is that there is no user with this username kai password.
    <form method=GET action=log1.jsp>
    <font size=5> Username <input type=text name="USERNAME" size=20>
              </font>
              <br>
              <font size=5> Password <input type=text name="PASSWORD" size=20>
              </font>
              <br>
              <input type=submit name=action value="Submit">
    </form>
    That's the forms and combined with the code in the fist post should have worked. Any ideas?
    thanks again.

  • Invalid cursor state error while executing the prepared statement

    hai friends,
    following code showing the invalid cursor state error while executing the second prepared statement.
    pls anyone help me
    String query = "select * from order_particulars where order_no=" + orderno + " order by sno";             psmt1 = conEntry.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);             rs1 = psmt1.executeQuery();             rs1.last();             intRowCount = rs1.getRow();             particularsdata = new Object[intRowCount][6];             rs1.beforeFirst();             if (intRowCount >= 1) {                 for (int i = 0; rs1.next(); i++) {                     particularsdata[0] = i + 1;
    particularsdata[i][1] = rs1.getString(3);
    particularsdata[i][2] = Double.parseDouble(rs1.getString(4));
    rs1.close();
    psmt1.close();
    query = "SELECT sum(delqty) FROM billdetails,billparticulars WHERE order_no= " + orderno + " and " +
    "billdetails.bill_no = billparticulars.bill_no GROUP BY particulars ORDER BY sno";
    psmt1 = conEntry.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    rs1 = psmt1.executeQuery(); //error showing while executing this line

    Also .. Why using arrays instead of collections? Shifting the cursor all the way forth and back to get the count is fairly terrible.
    With regard to the problem: either there's a nasty bug in the JDBC driver used, or you actually aren't running the compiled class version of the posted code.

  • Error handling in prepared statement batch

    Hi,
    For a prepared statement batch, it is not possible to know which operation failed. ... You should always perform a ROLLBACK operation in this situation.
    For a generic statement batch or callable statement batch, the update counts array is only a partial array containing the actual update counts up to the point of the error. ... You can either commit or roll back the successful operations in this situation, as you prefer.
    -- http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/oraperf.htm#1056233
    But, I want to skip failed operations and continue to excecute the remains of the batch, also, I want to improve application performance, what should I do? Is there any choice?
    Best Regards,
    Kevin Zhao

    According to the Oracle docs these are not the only possible values:
    Oracle9i JDBC Developer's Guide and Reference
    Release 2 (9.2) chapter 12
    Performance Extensions
    "For a prepared statement batch, it is not possible to know which operation failed. The array has one element for each operation in the batch, and each element has a value of -3. According to the JDBC 2.0 specification, a value of -3 indicates that an operation did not complete successfully. In this case, it was presumably just one operation that actually failed, but because the JDBC driver does not know which operation that was, it labels all the batched operations as failures."
    It goes on to say that for a generic statement batch it is possible to know which failed. I would like to know if similar functionality will be available for prepared statement batches in the future.

  • Db2 - bea jdbc type 4 driver error - cursor not in a prepared state

    Hi
    I am getting this error from BEA DB2 Driver in weblogic console.
    java.sql.SQLException: [BEA][DB2 JDBC Driver][DB2]CURSOR C02 NOT IN A
    PREPARED STATE
    This problem occurs frequently almost everyday.
    When this error happens we clear the statement cache by logging in to the weblogic console (which clears the cache of prepared and callable statements maintained for each connection in the connection pool), and will be able to proceed till the error comes up again!
    Has anyone come across this type of error?
    DB2 UDB V8.1 Fixpack 4 on Solaris
    Weblogic V8.1 SP2
    Thanks
    Sireesh.

    We have seen that error as well. When using entity beans, we could do some creates, but then we would get the Cursor error. It would happen sporadically.
    IBM now has better Type 4 drivers with version 8.2, we are having better luck with them then with the BEA drivers.

  • URGENT :::: Prepared Statement : Invalid Conversion Error

    Hi,
    I have prepared statement to update a database record. It is working fine but sometime it throws follow. SQLException. I checked the data I'm passing to the prepared statement. Everything works fine on the desktop but sometime it throws the foolow. exception on the websphere server.
    Error = SQL ERROR -99999 [IBM][CLI Driver] CLI0102E Invalid conversion. SQLSTATE=07006 In Method = performBulkOperation Of Class = com.bbh.actionworld.bulksql.BulkProcessing
    Its an urgent problem. Could you please help me ?
    thanks in advance.

    Hi
    I am using a prepared statement to insert records into an RDBMS. I am using JDK 1.4.1. I use setTime to set the date fields.
    My statement is
    pstmtAddFC.setTime(15, Time.valueOf("00:00:00"),
    Funcs.getCalendar(mydate));
    Where getCalendar sets the calandar to the date specified in mydate.
    I am using the JDBC:ODBC driver to connect to the database.
    This works fine with Oracle but gives
    java.SQL.Exception: [IBM][CLI Driver] CLI0102E Invalid Conversion. SQL STATE =07006
    Any suggestions? Thanks
    Regards
    Lakshmi

  • How do I handle NULL returns from prepared statement?

    Thanks in advance to all those who respond. As a beginner with Java/JSP/JDBC, I need all the help I can get!
    Here's the problem...
    I'm using a prepared statement in JSP to query a MySQL database.
    If there is a value to return, everything works properly.
    If the query returns a NULL (empty set) value, I get the following error:
    javax.servlet.ServletException: Before start of result set
    Here's the code (no negative comments please...I know I'm violating some conventions! I'll restructure it later. Right now I just need help with handling the NULL case):
    <%
    Driver DriverAppt = (Driver)Class.forName(MM_test_DRIVER).newInstance();
    Connection ConnAppt = DriverManager.getConnection(MM_test_STRING,MM_test_USERNAME,MM_test_PASSWORD);PreparedStatement StatementAppt = ConnAppt.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id = " + Recordset1__MMColParam + " AND year = " + yy + " AND month = '" + months[mm] + "' AND date = " + dates[dd] + " AND appttime = '16:15:00'");
    ResultSet Appt = StatementAppt.executeQuery();
    boolean Appt_isEmpty = !Appt.first();
    boolean Appt_hasData = !Appt_isEmpty;
    Object Appt_data;
    int Appt_numRows = 0;
    %>
    Thanks for the help!!!

    I think I have a better handle on what's occurring here. To cut to the heart of the problem, I'm going to give a very simple example that illustrates what type of error handling I need.
    HERE'S THE EXAMPLE:
    Let's say that I have a database of users. There are only two columns in the database: user_id and lastname. There are only 2 users, user_id "1" has lastname "Jones" and user_id "2" has lastname "Smith".
    I built a very simple web interface that let's a user enter a number to see if there's a lastname associated with that record. The user has no way of knowing if the user_id exists or not, so they may or may not enter a valid number.
    If the user enters a valid user_id (in this case "1" or "2"), then the correct lastname is displayed. If the user enters an invalid user_id (in this case, anything other than "1" or "2") then I get the same "Before start of result set" error that I'm getting in my real application.
    So, the question is: WHERE IN THIS CODE WOULD I HANDLE THE RETURN OF AN EMPTY SET?
    The goal here is to have the sentence say "The user's lastname is .", basically returning null. If there has to be a value, then have the last sentence say "The user's lastname is unknown."
    If you can solve this simple example, you'll have also solved the problem with my main application!!!! :-)
    Here's the example code:
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <%@ include file="Connections/example.jsp" %>
    <%
    String Recordset1__MMColParam = "1";
    if (request.getParameter("user_id") !=null) {Recordset1__MMColParam = (String)request.getParameter("user_id");}
    %>
    <%
    Driver DriverRecordset1 = (Driver)Class.forName(MM_example_DRIVER).newInstance();
    Connection ConnRecordset1 = DriverManager.getConnection(MM_example_STRING,MM_example_USERNAME,MM_example_PASSWORD);
    PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT * FROM test_table WHERE user_id = " + Recordset1__MMColParam + "");
    ResultSet Recordset1 = StatementRecordset1.executeQuery();
    boolean Recordset1_isEmpty = !Recordset1.next();
    boolean Recordset1_hasData = !Recordset1_isEmpty;
    Object Recordset1_data;
    int Recordset1_numRows = 0;
    %>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form action="test.jsp" method="get" enctype="application/x-www-form-urlencoded" name="form1" target="_self">
    <p> Submit a user id and a lastname will be displayed.</p>
    <p>
    <input type="text" name="user_id">
    <input type="submit" name="" value="Submit">
    </p>
    </form>
    <p>The User's lastname is <%=(((Recordset1_data = Recordset1.getObject("lastname"))==null || Recordset1.wasNull())?"":Recordset1_data)%>.</p>
    </body>
    </html>
    <%
    Recordset1.close();
    StatementRecordset1.close();
    ConnRecordset1.close();
    %>
    A huge "THANK YOU!!!!" to all those who've helped me here!!!

  • Could not find prepared statement with handle %.

    Greetings. I've seen several posts for this error on the web, but no clear cut answers. I captured the code below in profiler, with the intention of replaying in mgmt studio.
    However, the attempt end in the following error: "Could not find prepared statement with handle 612."
    declare @p1 int
    set @p1=612
    declare @p2 int
    set @p2=0
    declare @p7 int
    set @p7=0
    exec sp_cursorprepexec @p1 output,@p2 output,N'@P0 int,@P1 int,@P2 int,@P3 int,@P4 bit',N'EXEC dbo.mySproc @P0,@P1,@P2,@P3,@P4 ',4112,8193,@p7 output,219717,95,NULL,1,0
    select @p1, @p2, @p7
    Something noteworthy is that my sproc only has 5 input parameters, but this makes it look like it has many more.
    How do I manipulate the code enough to make it work in mgmt studio? Thanks!
    TIA, ChrisRDBA

    In profiler you would normally see RPC:Starting and RPC:Completed. The statement shown in RPC staring is what you need to pick because as Erland explained, completed would show "funky" behavior.
    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    This posting is provided "AS IS" with no warranties, and confers no rights.
    My Blog |
    Team Blog | @Twitter
    Author: SQL Server 2012 AlwaysOn -
    Paperback, Kindle

  • Prepared statements related problem

    Hi,
    i have this strange problem with prepared statements i think.
    When i execute an insert query without prepared statements i works fine (always), when i use prepared statements it sometimes gives a db error saying i'm trying to insert a null value.
    The problem is that I'm not!!!
    If i were why does it work sometimes?
    It may be a bug but i don't know where to look for it... is it a prepared statements, application server or db2 problem?

    This is the code...
         public void insertArticolo(Articolo item) throws Exception {
              PreparedStatement ps = null;
                   try {          
                        StringBuffer sql = new StringBuffer("insert into RUW.RUWT1_ARTICOLO (");
                        sql.append("C_ENTE, C_CONCESSIONE,N_ANNO_RUOLO,N_PROGR_RUOLO,N_PARTITA,N_PROGR_PARTITA,N_PROGR_TRIBUTO, ");
                        sql.append("C_TRIBUTO, C_TIPO_UFF,C_UFFICIO,");
                        sql.append("C_TIPO_IMP, N_ANNO_IMP, L_CARICO, S_ARTICOLO");
                        sql.append(") values (");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?");
                        sql.append(")");
                        ps = connectionCreatePreparedStatement(sql.toString());
                        System.out.println(sql.toString());
                        KeyArticolo keyArticolo = item.getKeyArticolo();
                        KeyPartita keyPartita = keyArticolo.getKeyPartita();
                        Ente ente = keyPartita.getKeyRuolo().getEnte();
                        System.out.println("/"+ ente.getCodEnte()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getConcessione().getCodConc()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getAnnoRuolo()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getProgRuolo()+ "/");
                        System.out.println("/"+ keyPartita.getNumPartita()+ "/");
                        System.out.println("/"+ keyPartita.getProgPartita()+ "/");
                        System.out.println("/"+ item.getKeyArticolo().getProgArticolo()+ "/");
                        System.out.println("/"+ item.getCodEntrata()+ "/");
                        System.out.println("/"+ ente.getTipoUfficio()+ "/");
                        System.out.println("/"+ ente.getCodUfficio()+ "/");
                        System.out.println("/"+ item.getTipoImposta()+ "/");
                        System.out.println("/"+ item.getAnnoImposta()+ "/");
                        System.out.println("/"+ item.getCaricoOrigine()+ "/");
                        if (item.getDescArticolo().equals("")) {
                             item.setDescArticolo(" ");
                        System.out.println("/"+ item.getDescArticolo()+ "/");
                        ps.setLong(1,ente.getCodEnte());
                        ps.setLong(2,keyPartita.getKeyRuolo().getConcessione().getCodConc());
                        ps.setLong(3,keyPartita.getKeyRuolo().getAnnoRuolo());
                        ps.setLong(4,keyPartita.getKeyRuolo().getProgRuolo());
                        ps.setLong(5,keyPartita.getNumPartita());
                        ps.setLong(6,keyPartita.getProgPartita());
                        ps.setLong(7,item.getKeyArticolo().getProgArticolo());
                        ps.setString(8,item.getCodEntrata());
                        ps.setString(9,ente.getTipoUfficio());
                        ps.setString(10,ente.getCodUfficio());
                        ps.setString(11,item.getTipoImposta());
                        ps.setLong(12,item.getAnnoImposta());
                        ps.setLong(13,item.getCaricoOrigine());
                        ps.setString(14,item.getDescArticolo());
                        ps.executeUpdate();
                   catch (Exception e) {
                        e.printStackTrace();
                        connectionCloseStatement(ps);
                        throw e;
              }and this is the result of the systemout
    [10/03/06 14.07.07:051 CET] 76357635 SystemOut O insert into RUW.RUWT1_ARTICOLO (C_ENTE, C_CONCESSIONE,N_ANNO_RUOLO,N_PROGR_RUOLO,N_PARTITA,N_PROGR_PARTITA,N_PROGR_TRIBUTO, C_TRIBUTO, C_TIPO_UFF,C_UFFICIO,C_TIPO_IMP, N_ANNO_IMP, L_CARICO, S_ARTICOLO) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    /13199/
    /66/
    /2002/
    /1564/
    /28330/
    /1/
    /2/
    /0997/
    /120/
    /2002/
    /11900/
    / /

  • Prepared statement help

    Hello all!
    I am trying to get this prepared statement to work but am getting an error that I cant understand.
    Basically I have a class file that the ps resides in. I am calling the ps from a jsp.
    Here is the code:
    public void recordUsage(String userid, String ipaddress, String page, String filename)
           String insertStatement = "INSERT INTO usageLog(userId,ipAddress, localTime, page, fileName) VALUES(?,?,?,?,?)";
                try
                {   java.util.Date currentDate=new java.util.Date();//Create a date object for the timestamp
                    java.sql.Timestamp ts=new java.sql.Timestamp(currentDate.getTime());//Create the timestamp from the above date object.
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    objConn = java.sql.DriverManager.getConnection("jdbc:odbc:sensorWeek","","");
                    PreparedStatement ps = objConn.prepareStatement(insertStatement);
                    ps.setString(1, userid);
                    ps.setString(2, ipaddress);
                    ps.setTimestamp(3, ts);
                    ps.setString(4, page);
                    ps.setString(5, filename);
                    ps.executeUpdate();
                    objConn.commit();
                    ps.close();
                    objConn.close();
                    System.out.println("recordusage method called");
                catch (SQLException s)
                    System.err.println("DataBase PROBLEM");
                    s.printStackTrace();
                catch (Exception e)
                        System.err.println("Error in recordUsage method");
                        e.printStackTrace();
    }Here is the error generated:(I hate to dump this on you)
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: sensorPac.methodClass.record(Ljava/lang/String;Ljava/lang/String;)V
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         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.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         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:2416)
         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.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:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
         at java.lang.Thread.run(Thread.java:534)
    root cause
    javax.servlet.ServletException: sensorPac.methodClass.record(Ljava/lang/String;Ljava/lang/String;)V
         at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
         at org.apache.jsp.download_jsp._jspService(download_jsp.java:93)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         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.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         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:2416)
         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.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:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
         at java.lang.Thread.run(Thread.java:534)
    TIA!!

    And what makes you think that the above code is causing the problem?

Maybe you are looking for

  • Jave Script error when opening any page.

    Whenever I load a page into Firefox I get the following error message: "[javascript application] Type Error: Components Class [CID] is undefined" This has happened with the last few versions of Firefox.

  • CS6 Indesign files not fully loading

    I have just purchased CS6 and created a few InDesign files. Now, on numerous occasions, when I try to open an existing file (not just one particular file), the file doesn't fully load. It shows some of the frame outlines and the graphic "content grab

  • Special characters through gateway !

    Hi, I've a portlet. In Edit->preferences, I've a textarea where user can enter <HTML> content. If user enters " " for a extra space and hit finish, it is replaced by junk character like "__" . Response.Type="text/html". I'm using GDK.

  • How can I add an arabic font in Photoshop CS5?

    Hi..I have windows 7, and am using photoshop CS5. I have an arabic font installed in my control panel thus i can use it in all other programs..except for photoshop. I cant view that arabic font in the photoshop fonts drop down box. I would really app

  • Non-Recoverable Tax Accounting for Purchasing of OPM Item

    Hi, As an industry practice and standard functionality of Oracle Inventory, Non-Recoverable TAX (tax paid upon purchase of items is not recovered through sales tax) is charged to the Inventory. However, this functionality is not available in OPM Inve