Prepared statement parameter order?

We have prepared statements for insert and update where changing the order of columns in the statement gives different results.
Problem 1:
For an update statements setting 8 column values via preparedStatement.executeUpdate, we got the following exception containing an internal error:
java.sql.SQLException: Interner Fehler: Daten-Array nicht zugewiesen
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
at oracle.jdbc.dbaccess.DBDataSetImpl._setDBItem(DBDataSetImpl.java:365)
at oracle.jdbc.dbaccess.DBDataSetImpl._bindsRowCompleted(DBDataSetImpl.java:737)
at oracle.jdbc.dbaccess.DBDataSetImpl.rowCompleted(DBDataSetImpl.java:1619)
at oracle.jdbc.driver.OraclePreparedStatement.get_data_for_columns(OraclePreparedStatement.java:2343)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:362)
All statement ? parameters where bound correctly.
When we changed the order of the update's set-clauses and of the according setString parameters to the same order the table is created in the database, the statement works fine.
Problem 2:
An insert statement using a VALUES clause with not more than 10 columns works fine independent of the column order.
But if we have a table with more than 10 columns, the insert only works if the columns in the insert statement are in the same order as the database table. Otherwise we got an IndexOutOfBoundsException - looks like a array overflow in an internal array used to sort column indexes...
We are using Oracle 8.1.7 and JDBC 1.2 thin driver.
Anyone else with similar problems?

Did you try to define the Parameter name?
Like these:
strSQL="XXX(p_1=>?, p_2=>?,p_3=>?)"
cstmt.setXXX(1,'v1');
cstmt.setXXX(3,'v3');
cstmt.setXXX(2,'v2');
I am suprised, If you have so many parameter, how can you maintain you code if you do not define the parameter names?

Similar Messages

  • Prepared Statement with ORDER BY

    I am trying to use order by with prepared statement but it is not ordering.
    String sql = "SELECT * FROM MATERIAL WHERE (LOWER(NAMEE) LIKE ('%' || ? || '%') ORDER BY ? ";
    PreparedStatement ps=CM.getStatement(sql);
    ps.setString(1,p);
    ps.setString(2,sort);
              ResultSet r = ps.executeQuery();
    Can any one tell me how do I use prepared statement with order by

    You can not parameterize column names and such, only literals. You should build the ORDER BY clause dynamically.

  • Describe a parameter from a prepared statement

    With OCI programming, is it possible to describe a prepared statement parameter information such as the parm's OCI_ATTR_CHARSET_FORM? if possible how to check the parm information?
    example:
    sword rt;
    wchar_t* cmd = L"select * from b3 where c2 = :1";
    wchar_t* data = L"adfa";
    short indicator = 0;
    if(rt = OCIStmtPrepare(hpStmt, hpErr, (OraText*)cmd, (ub4)wcslen(cmd)*2, OCI_NTV_SYNTAX, OCI_DEFAULT))
    checkerr(hpErr, rt);
    iReturn = -1;
    goto EXIT;
    if(rt = OCIBindByName(hpStmt, &hpBind, hpErr, (OraText *)L":1", (sb4)4, (dvoid *)data, 4, SQLT_STR, (dvoid *)&indicator, 0, 0, 0, 0,OCI_DEFAULT))
    checkerr(hpErr, rt);
    iReturn = -1;
    goto EXIT;
    how to get parm :1 information?
    if parm :1 charset form is SQLCS_NCHAR, I need set the parm's charset form before execute the statement by:
    //ub1 cform = SQLCS_NCHAR;
    //OCIAttrSet(hpBind, (ub4) OCI_HTYPE_BIND, (dvoid *) &cform, (ub4) 0, (ub4) OCI_ATTR_CHARSET_FORM, hpErr);
    If I directly set parm's form to SQLCS_NCHAR, it would bring performance problem.
    Thanks

    String date;
    String sql = "Select Accepts.TimeOfAccept FROM Accepts where Accepts.TimeOfAccept = 'jComboBox2';";
    ResultSet result = stmt.executeQuery(sql);
    date = result.getString("TimeOfAccept");
    String day = date.substring(0, 2);
    String month = date.substring(3, 5);
    String year = date.substring(6);
    i have fixed it to a point but before i get the substring i am supposed to check the formats of the metadata in case the format of the date changes the query is supposed to build dynamically off the meta data as a but i dont know how to do this i am accessing an access database to test it initially but i will be moving it onto an sql database where the date format may differ
    thanking you in advance

  • Pass table name as parameter in prepared Statement

    Can I pass table name as parameter in prepared Statement
    for example
    select * from ? where name =?
    when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
    I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
    Thanks
    Haroon Idrees.

    haroonob wrote:
    I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
    Well, I would say (ugly as it is) String concatenation, or stored procedures.

  • Dynamically obtain parameter count for a prepared statement

    Hi JDBC Gurus,
    Given a prepared statement, is there a way to figure out the parameter count at runtime? I need this info. to prompt the user for parameter values at the right time from my GUI tool. Any help will be greatly appreciated.

    i don't know of any way to do this put perusing through the API i am wondering what the getMetaData method of PreparedStatement is supposed to do. it says returns the meta data of a ResultSet's columns but i think it could contain info about the parameters for the PreparedStatement. i guess i just don't see why that method is there... anyone?

  • Prepared statement order by

    I have a problem with order by status in a prepared statement. The list is generated with no order by. However I can not find the error in code.
    Tomcat log print out the query as "com.mysql.jdbc.ServerPreparedStatement[1] - SELECT * FROM tm_game_tables order by 'name';"
    I call the bean from website with:
    <%
    ilia.admin.tm.ListTableBean ltb = new ilia.admin.tm.ListTableBean();
    ltb.setTm_order("name");
    %>
    <table>
    <%=ltb.getList()%>
    </table>Bean code:
    package ilia.admin.tm;
    import ilia.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class ListTableBean {
         String tm_order = "";
         public String getTm_order() {
              return tm_order;
         public void setTm_order(String tm_order) {
              this.tm_order = tm_order.trim();
         ConnectionPool pool = new ConnectionPool();
         Connection con = null;
         public String getList() throws ClassNotFoundException{
              String rt = ""; // String to return
              try{
                   con = pool.getConnection();
                   Object[] tm_type_array = {"Real Money", "Play Money"};
                   Object[] tm_status_array = {"Open", "Closed", "Maintance"};
                   PreparedStatement pStmt = con.prepareStatement("SELECT * FROM tm_game_tables order by ?;");
                   pStmt.setString(1, tm_order);
              System.out.println(pStmt);
                   ResultSet rs = pStmt.executeQuery();
                   if(!rs.next()){
                        rt = "";
                   else do {
                        rt = rt + "<tr><td>" + rs.getInt("table_id") + "</td>";
                        rt = rt + "<td>" + rs.getString("name") + "</td>";
                        rt = rt + "<td>" + tm_type_array[rs.getInt("type")] + "</td>";
                        rt = rt + "<td>$" + rs.getDouble("buy_in") + "</td>";
                        rt = rt + "<td>" + rs.getDouble("rake") + "%</td>";
                        rt = rt + "<td>" + tm_status_array[rs.getInt("status")] + "</td>";
                        rt = rt + "<td>" + rs.getString("url_background_image") + "</td>";
                        rt = rt + "<td>" + rs.getString("password") + "</td>";
                        rt = rt + "<td>" + rs.getString("update") + "</td>";
                        rt = rt + "<td>" + rs.getString("user") + "</td></tr>";
                   } while(rs.next());
                   pStmt = null;
                   rs = null;
              catch(Exception exp){
                   System.out.println("Exception: "+ exp);
              finally{
                   pool.putConnection(con);
              return rt;
    }If I test the query as per logs in mysql prompt I get the order by I want,
    Regards
    Andreas

    Still don't order them:
    Print out same query in tomcat log.
    Bean is now:
    package ilia.admin.tm;
    import ilia.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class ListTableBean {
         String tm_order = "";
         public String getTm_order() {
              return tm_order;
         public void setTm_order(String tm_order) {
              this.tm_order = tm_order.trim();
         ConnectionPool pool = new ConnectionPool();
         Connection con = null;
         public String getList() throws ClassNotFoundException{
              String rt = ""; // String to return
              try{
                   con = pool.getConnection();
                   Object[] tm_type_array = {"Real Money", "Play Money"};
                   Object[] tm_status_array = {"Open", "Closed", "Maintance"};
                   PreparedStatement pStmt = con.prepareStatement("SELECT * FROM tm_game_tables order by ?;");
                   pStmt.setString(1, tm_order);
                   ResultSet rs = pStmt.executeQuery();
              System.out.println(pStmt);
                   if(!rs.next()){
                        rt = "";
                   else do {
                        rt = rt + "<tr><td>" + rs.getInt("table_id") + "</td>";
                        rt = rt + "<td>" + rs.getString("name") + "</td>";
                        rt = rt + "<td>" + tm_type_array[rs.getInt("type")] + "</td>";
                        rt = rt + "<td>$" + rs.getDouble("buy_in") + "</td>";
                        rt = rt + "<td>" + rs.getDouble("rake") + "%</td>";
                        rt = rt + "<td>" + tm_status_array[rs.getInt("status")] + "</td>";
                        rt = rt + "<td>" + rs.getString("url_background_image") + "</td>";
                        rt = rt + "<td>" + rs.getString("password") + "</td>";
                        rt = rt + "<td>" + rs.getString("update") + "</td>";
                        rt = rt + "<td>" + rs.getString("user") + "</td></tr>";
                   } while(rs.next());
                   pStmt = null;
                   rs = null;
              catch(Exception exp){
                   System.out.println("Exception: "+ exp);
              finally{
                   pool.putConnection(con);
              return rt;
    }However if I change ststement to "PreparedStatement pStmt = con.prepareStatement("SELECT * FROM tm_game_tables order by " + tm_order + ";");" as earlier posted wrote I get the order by. However I think that is incorrect prepared statement standard, isn't it?
    Regards
    Andreas

  • Bug in Oracle JDBC thin driver (parameter order)

    [ I'd preferably send this to some Oracle support email but I
    can't find any on both www.oracle.com and www.technet.com. ]
    The following program illustrates bug I found in JDBC Oracle thin
    driver.
    * Synopsis:
    The parameters of prepared statement (I tested SELECT's and
    UPDATE's) are bound in the reverse order.
    If one do:
    PreparedStatement p = connection.prepareStatement(
    "SELECT field FROM table WHERE first = ? and second = ?");
    and then bind parameter 1 to "a" and parameter to "b":
    p.setString(1, "a");
    p.setString(2, "b");
    then executing p yields the same results as executing
    SELECT field FROM table WHERE first = "b" and second = "a"
    although it should be equivalent to
    SELECT field FROM table WHERE first = "a" and second = "b"
    The bug is present only in "thin" Oracle JDBC driver. Changing
    driver to "oci8" solves the problem.
    * Version and platform info:
    I detected the bug using Oracle 8.0.5 server for Linux.
    According to $ORACLE_HOME/jdbc/README.doc that is
    Oracle JDBC Drivers release 8.0.5.0.0 (Production Release)
    * The program below:
    The program below illustrates the bug by creating dummy two
    column table, inserting the row into it and then selecting
    the contents using prepared statement. Those operations
    are performed on both good (oci8) and bad (thin) connections,
    the results can be compared.
    You may need to change SID, listener port and account data
    in getConnecton calls.
    Sample program output:
    $ javac ShowBug.java; java ShowBug
    Output for both connections should be the same
    --------------- thin Driver ---------------
    [ Non parametrized query: ]
    aaa
    [ The same - parametrized (should give one row): ]
    [ The same - with buggy reversed order (should give no answers):
    aaa
    --------------- oci8 driver ---------------
    [ Non parametrized query: ]
    aaa
    [ The same - parametrized (should give one row): ]
    aaa
    [ The same - with buggy reversed order (should give no answers):
    --------------- The end ---------------
    * The program itself
    import java.sql.*;
    class ShowBug
    public static void main (String args [])
    throws SQLException
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new
    oracle.jdbc.driver.OracleDriver());
    System.out.println("Output for both connections should be the
    same");
    Connection buggyConnection
    = DriverManager.getConnection
    ("jdbc:oracle:thin:@localhost:1521:ORACLE",
    "scott", "tiger");
    process("thin Driver", buggyConnection);
    Connection goodConnection
    = DriverManager.getConnection ("jdbc:oracle:oci8:",
    "scott", "tiger");
    process("oci8 driver", goodConnection);
    System.out.println("--------------- The end ---------------");
    public static void process(String title, Connection conn)
    throws SQLException
    System.out.println("--------------- " + title + "
    Statement stmt = conn.createStatement ();
    stmt.execute(
    "CREATE TABLE bug (id VARCHAR(10), val VARCHAR(10))");
    stmt.executeUpdate(
    "INSERT INTO bug VALUES('aaa', 'bbb')");
    System.out.println("[ Non parametrized query: ]");
    ResultSet rset = stmt.executeQuery(
    "select id from bug where id = 'aaa' and val = 'bbb'");
    while (rset.next ())
    System.out.println (rset.getString (1));
    System.out.println("[ The same - parametrized (should give one
    row): ]");
    PreparedStatement prep = conn.prepareStatement(
    "select id from bug where id = ? and val = ?");
    prep.setString(1, "aaa");
    prep.setString(2, "bbb");
    rset = prep.executeQuery();
    while (rset.next ())
    System.out.println (rset.getString (1));
    System.out.println("[ The same - with buggy reversed order
    (should give no answers): ]");
    prep = conn.prepareStatement(
    "select id from bug where id = ? and val = ?");
    prep.setString(1, "bbb");
    prep.setString(2, "aaa");
    rset = prep.executeQuery();
    while (rset.next ())
    System.out.println (rset.getString (1));
    stmt.execute("DROP TABLE bug");
    null

    Horea
    In the ejb-jar.xml, in the method a cursor is closed, set <trans-attribute>
    to "Never".
    <assembly-descriptor>
    <container-transaction>
    <method>
    <ejb-name></ejb-name>
    <method-name></method-name>
    </method>
    <trans-attribute>Never</trans-attribute>
    </container-transaction>
    </assembly-descriptor>
    Deepak
    Horea Raducan wrote:
    Is there a known bug in Oracle JDBC thin driver version 8.1.6 that would
    prevent it from closing the open cursors ?
    Thank you,
    Horea

  • SELECT-INTO prepared statement?

    Hi,
    I have a single-row select to execute. I don't know if the multi-row select functionality (ResultSets, etc.) should be used for a single-select.
    Here's from the Oracle JDBC Documentation on a prepared statement with input variables:
    PreparedStatement pstmt =
    conn.prepareStatement ("insert into EMP (EMPNO, ENAME) values (?, ?)");
    pstmt.setInt (1, 1500); // The first ? is for EMPNO
    pstmt.setString (2, "LESLIE"); // The second ? is for ENAME
    pstmt.execute ();
    What I would like to do is have a PreparedStatement for output variables in a SELECT-INTO:
    pstmt= conn.prepareStatement("select max(sal) into ? from emp;");
    but there appears to be no bind variable functionality.
    Callable statements apparently are only for stored procedures.
    Basically, should I just use the multirow select for this?
    Thanks,
    Glen

    pstmt= conn.prepareStatement("select max(sal) into ?
    from emp;");
    but there appears to be no bind variable
    functionality.You might be able to bind this as an output parameter, but it seems like extra work (just getting a ResultSet for "select max(sal) from emp" would be a lot more straight forward).
    >
    Callable statements apparently are only for stored
    procedures.Not really, I execute PL/SQL blocks using prepared statements all the time. Sometimes it's the only way to get the data into a format that JDBC can handle.
    Here's an example:
        /** This is the SQL used to call the API ... */
        public static final String spSQL =  
        "declare " +
            "t_warranty_tbl apps.cib_devo_wrapper.wartbltyp; " +
            "x_warranty_tbl apps.cib_devo_wartbltyp; " +
            "x_return_text VARCHAR2(2000); " +
        "begin " +
            "apps.cib_devo_wrapper.cib_get_warranty_info(" +
                "P_SERIAL_NUMBER => ?,"
                "X_WARRANTY_TBL => t_warranty_tbl," +
                "X_RETURN_TEXT => x_return_text," +
                "x_row_count => ?); " +
            // Convert to a table of objects ...
            "x_warranty_tbl := apps.cib_devo_wrapper.cib_warranty_casttowartbltyp(t_warranty_tbl); " +
            // Get the cursor with order by ...
            "OPEN ? FOR SELECT * FROM TABLE(CAST(x_warranty_tbl AS apps.CIB_DEVO_WarTblTyp)) tbl " +
                "WHERE tbl.entitlementReturnCode != apps.cib_devo_wrapper.g_ent_ret_code_08 " +
                "ORDER BY tbl.INSTALLEDAT_CUSTOMER_NAME, tbl.SITE_NAME, tbl.SITE_ID, " +
                          "tbl.PRODUCT_FAMILY, tbl.PRODUCT_NAME, tbl.SERIAL_NUMBER; " +
           "?:=x_return_text; " +
        "end;";In this example, I declare a few variables, call a stored procedure,
    do some more PL/SQL to reduce the results before I finally bring them back.
    The first placeholder (question mark) is the input serial number, the second one is an output parameter that gives the row count. The third
    question mark is the cursor that contains the data I need, and the fourth is a reference to a status message.
    As you can see, the PL/SQL isn't exclusively stored procedure calls.
    >
    Basically, should I just use the multirow select for
    this?I think you'd need code that looks something like:
    DECLARE
    myCount NUMBER;
    BEGIN
    select max(sal) into myCount
    from emp;
    ? := myCount
    END;Although wrapping the select in a BEGIN..END block may be enough.

  • 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.

  • ArrayIndexOutOfBoundsException when setting a date in a prepared statement

    Hi,
    was wondering if anyone could help. I have a prepared statement, with two "variables" in it. I need to set the first of these to a string (using setString(1, "string)
    and the second to a date, using setDate(2, SQLDate)
    My SQL date is a valid date ass I've run a debugger and checked, but everytime setDate is called an Array Out Of Bound Exception is thrown. Can anyone shed any light on this as I'm rather confused as to why this is happening!
    Thanks in advance

    I havent got a small runnable example to hand, but taking an excert from my code I have:
    for (int i = 0; i < this.columnNames.size();i++)
    singleDateEventFlagSingleArea.setString(1, newAreaName);
    singleDateEventFlagSingleArea.setDate(2, Date.valueOf((String) this.columnNames.get(i)));
    eventFlagsResult = singleDateEventFlagSingleArea.executeQuery()
    }newAreaName is a argument passed to the method. columnNames is a vector of dates/strings, which I parse back into a date to pass to the setDate method
    Where the value of the date in the statement is changed to a preset value each iteration.
    The exception stack I'm getting is:
    exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
         at oracle.jdbc.dbaccess.DBDataSetImpl._getDBItem(DBDataSetImpl.java:378)
         at oracle.jdbc.dbaccess.DBDataSetImpl._createOrGetDBItem(DBDataSetImpl.java:781)
         at oracle.jdbc.dbaccess.DBDataSetImpl.setBytesBindItem(DBDataSetImpl.java:2399)
         at oracle.jdbc.driver.OraclePreparedStatement.setItem(OraclePreparedStatement.java:1134)
         at oracle.jdbc.driver.OraclePreparedStatement.setDate(OraclePreparedStatement.java:2223)
         at treeTableVersion2.TreeTable.updateValuesSingleDateSingleArea(TreeTable.java:393)
         at treeTableVersion2.TestWindow.actionPerformed(TestWindow.java:394)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
         at java.awt.Component.processMouseEvent(Component.java:5488)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
         at java.awt.Component.processEvent(Component.java:5253)
         at java.awt.Container.processEvent(Container.java:1966)
         at java.awt.Component.dispatchEventImpl(Component.java:3955)
         at java.awt.Container.dispatchEventImpl(Container.java:2024)
         at java.awt.Component.dispatchEvent(Component.java:3803)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
         at java.awt.Container.dispatchEventImpl(Container.java:2010)
         at java.awt.Window.dispatchEventImpl(Window.java:1774)
         at java.awt.Component.dispatchEvent(Component.java:3803)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)Although I think a lot of that is because the process is called by a button press.
    The sql statement thats causing the problem is:
    select h.areaname,
           e.code,
           e.descript,
           ec.date_raised,
           ec.date_progressing,
           ec.date_completed
      from hareas h, evt_type e, evt_core ec
    where h.areaname = ?
       and e.evt_type_id = ec.evt_type_id
       and (h.nblink = ec.area1_nblink or h.nblink = ec.area2_nblink)
       and ec.date_raised = ?
    group by h.areaname,
              e.code,
              e.descript,
              ec.date_raised,
              ec.date_progressing,
              ec.date_completed
    order by h.areanameThanks for your help

  • SetString in Prepared Statement

    Help!
    I am trying to use a prepared statement and use a setString. It seems to work when I use a value as the parameter, but when I pass it a variable I get an error. Any ideas???
    THIS WORKS.....
    String buffer;
    String selectStmt1 = "SELECT veh_key_i FROM yzdbdat.mxtp010_veh " +
    "WHERE veh_chass_no = ?";
    PreparedStatement selectVehKey = connection.prepareStatement(selectStmt1);
    selectVehKey.setString(1,"2H412152");
    ResultSet getVehicle = selectVehKey.executeQuery();
    THIS DOESN'T...I GET A RIGHT TRUNCATION ERROR
    String buffer;
    String selectStmt1 = "SELECT veh_key_i FROM yzdbdat.mxtp010_veh " +
    "WHERE veh_chass_no = ?";
    PreparedStatement selectVehKey = connection.prepareStatement(selectStmt1);
    selectVehKey.setString(1,buffer);
    ResultSet getVehicle = selectVehKey.executeQuery();
    THANKS!!

    A right truncation error? I would have expected a NullPointerException, since you haven't assigned anything to that variable. But if your real code does assign something to it, then probably it is too long to fit in the database column.

  • Using Like Clause in Prepared Statement

    Hi,
    I want to use LIKE clause in prepared statement. This is not returning any record.
    This is the query. Please help me in this.
    SELECT EMPLYR_GRP,EMPLYR_GRP_NAME FROM EMPLOYER_GROUP WHERE EMPLYR_GRP_NAME LIKE ? AND EMPLYR_GRP = ?
    This is giving Oracle SQL Error.
    SELECT EMPLYR_GRP,EMPLYR_GRP_NAME FROM EMPLOYER_GROUP WHERE EMPLYR_GRP_NAME LIKE %?% AND EMPLYR_GRP = ?

    The first variant should work just fine as long as you use stmt.setString(1, '%' + pattern + '%') to set the parameter. The second query is just plain wrong.
    Alin.

  • Setting date to null in prepared statement

    Can anyone tell me how to set a date in Oracle to null using prepared statements.
    prepared.setDate

    Have you tried using the setNull parameter? The following should work for you. (I haven't tested it.)
    prepared.setNull(1, Types.DATE);

  • Weblogic generated finder method not setting parameters in prepared statement

    Hi,
    I am using weblogic 6.1 sp2 and have a CMP bean with a finder defined as follows:
    <query>
    <query-method>
    <method-name>findByPcPayclass</method-name>
    <method-params>
    <method-param>java.lang.String</method-param>
    </method-params>
    </query-method>
    <ejb-ql>SELECT DISTINCT OBJECT(p) FROM Payments p, PaymentType
    t WHERE p.paymentType.pcPayClass = '?1'</ejb-ql>
    </query>
    The weblogic generated code follwos:
    public java.util.Collection ejbFindByPcPayclass(java.lang.String param0) throws
    javax.ejb.FinderException
    if(__WL_verbose) {
    Debug.say("called findByPcPayclass");
    java.sql.Connection __WL_con = null;
    java.sql.PreparedStatement __WL_stmt = null;
    java.sql.ResultSet __WL_rs = null;
    __WL_pm.flushModifiedBeans();
    try {
    __WL_con = __WL_pm.getConnection();
    } catch (java.lang.Exception e) {
    __WL_pm.releaseResources(__WL_con, __WL_stmt, __WL_rs);
    throw new javax.ejb.FinderException("Couldn't get connection: " + EOL +
    e.toString() + EOL +
    RDBMSUtils.throwable2StackTrace(e));
    try {
    java.lang.String __WL_query = "SELECT WL0.DEPOSIT_UID, WL0.GLA_ID, WL0.MARKET_CODE,
    WL0.ORIGINAL_PAYMENT_ID, WL0.PAYMENT_ACCT_NUMBER, WL0.PAYMENT_ACK, WL0.PAYMENT_AMOUNT,
    WL0.PAYMENT_CARD_CHECK_NUM, WL0.PAYMENT_CARE_SITE, WL0.PAYMENT_CUST_NAME, WL0.PAYMENT_DESIGNATOR,
    WL0.PAYMENT_EFFECTIVE_DATE, WL0.PAYMENT_ID, WL0.PAYMENT_INV_ID, WL0.PAYMENT_MOBILE_NUMBER,
    WL0.PAYMENT_SPLIT, WL0.PC_PAYCLASS, WL0.PT_UID, WL0.TT_UID FROM payment_type
    WL2, payment_type WL1, payments WL0 WHERE (WL2.PC_PAYCLASS = '?1') AND WL0.PT_UID
    = WL2.PT_UID " + __WL_pm.selectForUpdate();
    if(__WL_verbose) {
    Debug.say("Finder produced statement string " + __WL_query);
    __WL_stmt = __WL_con.prepareStatement(__WL_query);
    // preparedStatementParamIndex reset.
    __WL_rs = __WL_stmt.executeQuery();
    } catch (java.lang.Exception e) {
    __WL_pm.releaseResources(__WL_con, __WL_stmt, __WL_rs);
    throw new javax.ejb.FinderException(
    "Exception in findByPcPayclass while preparing or executing " +
    "statement: '" + __WL_stmt + "'" + EOL +
    e.toString() + EOL +
    RDBMSUtils.throwable2StackTrace(e));
    The parameter is never set in the prepared statement before it executes. This
    causes the finder to return an empty result set. Is this a bug or is there some
    configuration that I missed. I am using ant 1.5 to do the ejbc. the ant target
    follows:
    <target name="ccas.ejbc" depends="ccas.compile, ccas.stage, dd.combine">
    <ejbjar srcdir="${buildClasses}/"
    descriptordir="${buildOutput}/ear_dd"
    basejarname="CCAS"
    flatdestdir="true"
    dependency="full">
    <support dir="${buildClasses}">
    <include name="CCAS/**/*.class"/>
    </support>
    <weblogic destdir="${ear.stage.dir}"
    rebuild="false"
    keepgenerated="true"
    jvmdebuglevel="16">
    <classpath refid="classpath"/>
    <wlclasspath refid="classpath"/>
    </weblogic>
    <include name="ejb-jar.xml"/>
    <exclude name="**/*-weblogic*.xml"/>
    </ejbjar>
    </target>

    replace '?1' with ?1
    "Eugene Stephens" <[email protected]> wrote in message
    news:[email protected]...
    >
    Hi,
    I am using weblogic 6.1 sp2 and have a CMP bean with a finder defined asfollows:
    <query>
    <query-method>
    <method-name>findByPcPayclass</method-name>
    <method-params>
    <method-param>java.lang.String</method-param>
    </method-params>
    </query-method>
    <ejb-ql>SELECT DISTINCT OBJECT(p) FROM Payments p,PaymentType
    t WHERE p.paymentType.pcPayClass = '?1'</ejb-ql>
    </query>
    The weblogic generated code follwos:
    public java.util.Collection ejbFindByPcPayclass(java.lang.String param0)throws
    javax.ejb.FinderException
    if(__WL_verbose) {
    Debug.say("called findByPcPayclass");
    java.sql.Connection __WL_con = null;
    java.sql.PreparedStatement __WL_stmt = null;
    java.sql.ResultSet __WL_rs = null;
    __WL_pm.flushModifiedBeans();
    try {
    __WL_con = __WL_pm.getConnection();
    } catch (java.lang.Exception e) {
    __WL_pm.releaseResources(__WL_con, __WL_stmt, __WL_rs);
    throw new javax.ejb.FinderException("Couldn't get connection: " +EOL +
    e.toString() + EOL +
    RDBMSUtils.throwable2StackTrace(e));
    try {
    java.lang.String __WL_query = "SELECT WL0.DEPOSIT_UID, WL0.GLA_ID,WL0.MARKET_CODE,
    WL0.ORIGINAL_PAYMENT_ID, WL0.PAYMENT_ACCT_NUMBER, WL0.PAYMENT_ACK,WL0.PAYMENT_AMOUNT,
    WL0.PAYMENT_CARD_CHECK_NUM, WL0.PAYMENT_CARE_SITE, WL0.PAYMENT_CUST_NAME,WL0.PAYMENT_DESIGNATOR,
    WL0.PAYMENT_EFFECTIVE_DATE, WL0.PAYMENT_ID, WL0.PAYMENT_INV_ID,WL0.PAYMENT_MOBILE_NUMBER,
    WL0.PAYMENT_SPLIT, WL0.PC_PAYCLASS, WL0.PT_UID, WL0.TT_UID FROMpayment_type
    WL2, payment_type WL1, payments WL0 WHERE (WL2.PC_PAYCLASS = '?1') ANDWL0.PT_UID
    = WL2.PT_UID " + __WL_pm.selectForUpdate();
    if(__WL_verbose) {
    Debug.say("Finder produced statement string " + __WL_query);
    __WL_stmt = __WL_con.prepareStatement(__WL_query);
    // preparedStatementParamIndex reset.
    __WL_rs = __WL_stmt.executeQuery();
    } catch (java.lang.Exception e) {
    __WL_pm.releaseResources(__WL_con, __WL_stmt, __WL_rs);
    throw new javax.ejb.FinderException(
    "Exception in findByPcPayclass while preparing or executing " +
    "statement: '" + __WL_stmt + "'" + EOL +
    e.toString() + EOL +
    RDBMSUtils.throwable2StackTrace(e));
    The parameter is never set in the prepared statement before it executes.This
    causes the finder to return an empty result set. Is this a bug or is theresome
    configuration that I missed. I am using ant 1.5 to do the ejbc. the anttarget
    follows:
    <target name="ccas.ejbc" depends="ccas.compile, ccas.stage,dd.combine">
    <ejbjar srcdir="${buildClasses}/"
    descriptordir="${buildOutput}/ear_dd"
    basejarname="CCAS"
    flatdestdir="true"
    dependency="full">
    <support dir="${buildClasses}">
    <include name="CCAS/**/*.class"/>
    </support>
    <weblogic destdir="${ear.stage.dir}"
    rebuild="false"
    keepgenerated="true"
    jvmdebuglevel="16">
    <classpath refid="classpath"/>
    <wlclasspath refid="classpath"/>
    </weblogic>
    <include name="ejb-jar.xml"/>
    <exclude name="**/*-weblogic*.xml"/>
    </ejbjar>
    </target>

  • Prepared Statement, executing  SELECT TOP in Ms Access

    I'm having the following problem. I built an application fetching data without any problem from MS SQL Server, this was using prepared statements. Now i'm having this strange problem with the following query:
    SELECT TOP 1 *
    FROM table
    WHERE appliance_id = ?
    AND ttimestamp_initpk <= ?
    AND ((Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?))
    ORDER BY ttimestamp_initpk DESC
    While on SQL Server this fetches just a record, on MS Access it fetches the whole set of records without worrying about TOP instruction.
    That is, it acts like a SELECT * FROM, and this slows down runtime behaviour.
    I'm using sun.jdbc.odbc.JdbcOdbcDriver, is it the problem?
    Thanks, Mirko

    Thanks for your answer, but i'm not sure this is the reason.
    I made one more test: i wrote a .Net application connecting to a MS Access using an ODBC connection. SELECT TOP statement is working fine, so i think i'll try another JDBC driver. Any other solution??
    Thanks,
    Mirko

Maybe you are looking for

  • What is the best way of reading a browser cookie and writing to sessionbean

    Hi, So far I have happily written a cookie in the visting browser and happily can display with a browser using a servlet println etc But what is the best way to take that value and put it into say getSessionBean1().setCookieValue("Cookievalue"); I wa

  • How I save text to a PDF so that I can email the changes?

    I just downloaded adobe acrobat reader for my iPhone 4S. Every time I add text to a PDF and then email it, the recipients never receive the annotated file. They only receive a blank PDF. I don't see any feature to save changes. Please help.

  • Display Weather in Portlet

    How can I display weather for specific cities in my portlet? null

  • Converting files to InDesign CS3 from Illustrator

    We have lot of files needs to be converted from Illustrator to InDesign CS3. How can it be done? We have tried but it is coming as an image & can not modify anything.

  • SSID showing

    SSID showing even though SSID broadcast is disabled. I had originally set SSID Broadcast to enabled as I was setting it up.  But when I disabled it, it was still showing on my laptop when I was viewing available wireless networks. This was even if it