Prepared Statement and DEFAULT identifier

Does anyone know how to pass the identifier DEFAULT to a PreparedStatement?
I am processing a text file to import into a database table (Oracle 9i) via JDBC. The user is able to configure what will happen if the data in the file doesn't match the types required by the database and so I do a quick check that the data is of the right type before it gets to the database. The user can choose to have the invalid value replaced with the default associated with that field (as configured on the database table). Eg. Table setup is
CREATE TABLE "TEST1" (
"TESTFIELD1" VARCHAR2(40 byte),
"TESTFIELD2" VARCHAR2(40 byte) NOT NULL,
"TESTFIELD3" NUMBER(30, 10) DEFAULT 777)
sample data of 'abc', 'def', 'www' should therefore end up as 'abc', 'def', 777
The problem I have is that I'm using a PreparedStatement to do the INSERTs (there could potentially be thousands of them).
The following SQL is what I'm trying to emulate...
INSERT INTO table (field1, field2, field3) VALUES ('abc', 'def', DEFAULT);
BUT, I am using a PreparedStatment via JDBC with bind variables ...
pstmt = con.prepareStatement("INSERT INTO table (field1, field2, field3) VALUES (?, ?, ?)");
ps.setString(1, "abc");
ps.setString(2, "def");
ps.setsomething(3, something); <- what goes here?
I have no idea what to put in the "something" bits so that DEFAULT is passed through. I obviously can't use setString(3, "DEFAULT"); as I'll just get an Oracle type mismatch error.
I realise that I could just leave out the 3rd variable and the default would be inserted automatically - but because some of the rows in the input file may have a valid value for field3 I don't always want the default value. Using the straight SQL is not an option due to the performance (or lack thereof).
Any ideas would be greatly appreciated! Thanks!

As for the best of my knowledge if you set the value to be null in the prepared Statement while setting that
for insert statement internally it is set to DEFAULT in ORACLE..
More over i thought that this will be usefull for u..
setNull
public void setNull(int paramIndex,
int sqlType,
String typeName)
throws SQLExceptionSets the designated parameter to SQL NULL. This version of the method setNull should be used for user-defined types and REF type parameters. Examples of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and named array types.
setNull
public void setNull(int parameterIndex,
int sqlType)
throws SQLExceptionSets the designated parameter to SQL NULL.
Note: You must specify the parameter's SQL type.
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
sqlType - the SQL type code defined in java.sql.Types
Throws:
SQLException - if a database access error occurs
ALL THE BEST

Similar Messages

  • Pooling Prepared Statement and Resultset

    Is their any mechanism in Weblogic by which we can pool prepared statements and
    resultset.

    Yes you can cache prepared statements. The connection pool will
    automatically cache the prepared statements (10 prepared statement was the
    limit in previous so you may want to write some startup class to load the
    imp prepared statements.). When you reuse the prepared statement the
    connection pool will pick it from its prepared statement cache. In 6.1 you
    can configure the number of prepared statements that you want to cache.
    But you cannot have multiple resultsets open for the same statement object.
    You can have cache rows though.
    Please search the bea newsgroups for more info. There are a bunch of posts
    that will be helpful to you.
    http://search.bea.com/weblogic/gonews/
    sree
    "hogan" <[email protected]> wrote in message
    news:3bd9cf88$[email protected]..
    >
    Is their any mechanism in Weblogic by which we can pool preparedstatements and
    resultset.

  • Statement,Prepared Statement and callable statement

    Hi,
    Please let me know in which scenario we are using Statement,Prepared Statement and callable statement.
    and which is efficient one among the above.
    Thanks in advance

    Welcome to the forum!
    >
    Please let me know in which scenario we are using Statement,Prepared Statement and callable statement.
    >
    We don't know what scenario you are using those in or if you are using them at all. Are you asking what they are?
    For document related questions you should consult the documentation or use your favorite search engine to get information.
    See the Java Tutorial
    http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
    >
    The main feature of a PreparedStatement object is that, unlike a Statement object, it is given a SQL statement when it is created. The advantage to this is that in most cases, this SQL statement is sent to the DBMS right away, where it is compiled. As a result, the PreparedStatement object contains not just a SQL statement, but a SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement SQL statement without having to compile it first.
    >
    The Javadocs for your Java SDK have the API for each of those classes and a description of what they are. And the Oracle JDBC Developer Guide has extensive information on how to use them.
    http://docs.oracle.com/cd/B28359_01/java.111/b31224/toc.htm

  • MS SQL Server 7 - Performance of Prepared Statements and Stored Procedures

    Hello All,
    Our team is currently tuning an application running on WL 5.1 SP 10 with a MS
    SQL Server 7 DB that it accesses via the WebLogic jConnect drivers. The application
    uses Prepared Statements for all types of database operations (selects, updates,
    inserts, etc.) and we have noticed that a great deal of the DB host's resources
    are consumed by the parsing of these statements. Our thought was to convert many
    of these Prepared Statements to Stored Procedures with the idea that the parsing
    overhead would be eliminated. In spite of all this, I have read that because
    of the way that the jConnect drivers are implemented for MS SQL Server, Prepared
    Statments are actually SLOWER than straight SQL because of the way that parameter
    values are converted. Does this also apply to Stored Procedures??? If anyone
    can give me an answer, it would be greatly appreciated.
    Thanks in advance!

    Joseph Weinstein <[email protected]> wrote:
    >
    >
    Matt wrote:
    Hello All,
    Our team is currently tuning an application running on WL 5.1 SP 10with a MS
    SQL Server 7 DB that it accesses via the WebLogic jConnect drivers.The application
    uses Prepared Statements for all types of database operations (selects,updates,
    inserts, etc.) and we have noticed that a great deal of the DB host'sresources
    are consumed by the parsing of these statements. Our thought was toconvert many
    of these Prepared Statements to Stored Procedures with the idea thatthe parsing
    overhead would be eliminated. In spite of all this, I have read thatbecause
    of the way that the jConnect drivers are implemented for MS SQL Server,Prepared
    Statments are actually SLOWER than straight SQL because of the waythat parameter
    values are converted. Does this also apply to Stored Procedures???If anyone
    can give me an answer, it would be greatly appreciated.
    Thanks in advance!Hi. Stored procedures may help, but you can also try MS's new free type-4
    driver,
    which does use DBMS optimizations to make PreparedStatements run faster.
    Joe
    Thanks Joe! I also wanted to know if setting the statement cache (assuming that
    this feature is available in WL 5.1 SP 10) will give a boost for both Prepared Statements
    and stored procs called via Callable Statements. Pretty much all of the Prepared
    Statements that we are replacing are executed from entity bean transactions.
    Thanks again

  • Oracle Prepared Statement and spaces in field

    I have a field that is defined as char(10). It has characters like '39' in it. When I select against it using standard SQL (where clause) I get results. When I use it in the where clause of a prepared statement it does not return any rows.
    If I have the field defined as char(2) the prepared statement works.
    If I have the field defined as varchar2(10) and loaded with '39' the prepared statement works.
    If I have the field defined as varchar2(10) and loaded with '39 ' the prepared statement returns no results.
    I really do not think this is a JDBC problem. However, since Oracle's site basically <expletive deleted>, I am hoping someone here has a solution.
    Thanks in advance if you can help.

    Let me clarify.
    I cannot remove the whitespace from the data in the database. I do not need the whitespace to do the query if I am not using a Prepared Statement. This seems to be a problem with the way Oracle is handling the prepared statement. (hence.. my thinking that this is really not a JDBC problem at all.. but I could be wrong.)

  • Prepared Statement and Stored Procedure..

    I have about 200 SQL statement in my Java application
    I have two options either to convert into
    Stored procedures
    or to convert into prepared statement ....
    Please guide me which options should be best....
    I need difference
    1)in term of speed.
    2)Memory..
    Regards
    Mahesh
    Senior DBA

    club your statements on the basis of related functionalities and change it to stored procedures as it will redudce no. of calls to the database and will be faster to fetch data in one go and even reduce the memory requirements.

  • Prepared Statement and Stored Procedure difference?

    For SQL in my web applications I use PreparedStatement object alot in my JDBC working with Oracle 9i.
    I also heard the term Stored Procedure. What is the difference between Stored Procedure and Prepared Statement?

    I am new to java programming, can anybody explain
    what exactly precompiled means
    Thank you
    PalspaceWhat does you subject line have to do with your question?
    The difference between a stored proc and a prepared statement is mainly this.
    A stored proc is stored in the database server permanently and can be used and re-used from a different connections.
    A PreparedStatement is not valid across connections.
    Stored procs are almost always precompiled. (I am just hedging a bit here just in case but you can consider it 100%)
    PreparedStatements MAY be precompiled. Hard to say.
    Precompiling means at least one of and perhaps all of the following depending on the database
    - The parsing of the SQL statement
    - The checking of the SQL against the data dictionary to ensure that the tables and columns referenced actually exist
    - The preparation of a query plan
    Last but not least Stored procedures may (and often do) contain more than simple queries but are in fact relatively complex programs written in a DB specific language (an offshoot of SQL of some sort).

  • Prepared statement and DELETE returns 0 count

    when executing an oracle prepared statement, the count returned is allways 0 for DELETE. However, if doing an INSERT, the count returned is correct
    public void CreatePreparePurgeRcdSetArray(String sql, int i, int max, boolean create) throws SQLException,Exception
    if (create == true)
              if (preparedStatementArray == null)
                   preparedStatementArray = new PreparedStatement[max];
              int scroll_type = getScrollType();
                   if (sql.compareTo("NOT_USED") == 0)
                        preparedStatementArray[i] = null;
                   else
                        preparedStatement          = (connClass.getConn()).prepareStatement(sql);
                        preparedStatementArray[i] = preparedStatement;
                        preparedStatement          = null;
    else
         closePrepareStatementArray(max);
    public int UpdatePreparePurgeRcdSet(Vector smry, String sqlP, int i) throws SQLException,Exception
         Object[] searchs = (Object[])smry.elementAt(0);
         /*java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
         String aaa = searchs[1].toString();
         String aab = searchs[1].toString();
         java.util.Date                     dtx = sdf.parse(aaa);
         java.util.Date                     dty = sdf.parse(aab);
         oracle.sql.DATE aa1 = new DATE(new Timestamp(dtx.getTime()));
         oracle.sql.DATE aa2 = new DATE(new Timestamp(dty.getTime()));
         java.sql.Timestamp      ts1 = (java.sql.Timestamp) searchs[1] ;
         java.sql.Timestamp      ts2 = (java.sql.Timestamp) searchs[5] ;
         boolean oracle = true;
         boolean debug = true;
              if ((oracle == true) && (debug == true))
                   String sql1 = "INSERT INTO FFI_MASTER_PURGE_TBL values ('lmill', 'OSTDEVT', 'sdsadmin', ?, 30, 60, '0', 2, 'ZZZ', ' ')";
                   String sql2 = "DELETE FROM TDSADMIN.FFI_MASTER_PURGE_TBL where FORMATCATEGORY = ?";
                   String sql3 = "DELETE from TDSADMIN.SUMMARY_TBL where (ML_STI_SRC_SYS_CD = ?) AND (ML_STI_CYCLE_CD = ?) AND (ML_STI_FILE_ID = ?)";
                   preparedStatement = (connClass.getConn()).prepareStatement(sql3);
                   //preparedStatement.setString(1, "test");
                   preparedStatement.setString(1, "618");
                   preparedStatement.setString(2, "0114200601");
                   preparedStatement.setString(3, "00001591");
                   oraclePreparedStatement = (OraclePreparedStatement)preparedStatement;
                   recsDeleted = oraclePreparedStatement.executeUpdate();
              if (oracle == true)
              preparedStatement = preparedStatementArray;
              //oraclePreparedStatement.setExecuteBatch (3);
              // ML_STI_SRC_SYS_CD
              preparedStatement.setString(1, searchs[0].toString());
                   // ML_STI_SRCSYS_DTTM
              //preparedStatement.setTimestamp(2, ts1);
              //preparedStatement.setObject(2, aa1);
              // ML_STI_CYCLE_CD
              preparedStatement.setString(2, searchs[2].toString());
                   // ML_STI_FILE_ID
              preparedStatement.setString(3, searchs[3].toString());
                   // ML_STI_LOAD_DTTM
              //preparedStatement.setTimestamp(5, ts2);
              //preparedStatement.setObject(5, aa2);
         else
                   preparedStatement = preparedStatementArray[i];
              // ML_STI_SRC_SYS_CD
              preparedStatement.setString(1, searchs[0].toString());
                   // ML_STI_SRCSYS_DTTM
              preparedStatement.setTimestamp(2, ts1);
              // ML_STI_CYCLE_CD
              preparedStatement.setString(3, searchs[2].toString());
                   // ML_STI_FILE_ID
              preparedStatement.setString(4, searchs[3].toString());
                   // ML_STI_LOAD_DTTM
              preparedStatement.setTimestamp(5, ts2);
         DateClass dateClass = new DateClass();
              String startTime = dateClass.calToFormattedDateExact();
              try
                   if (oracle == true)
                        //int batch_val = oraclePreparedStatement.getExecuteBatch();
                        oraclePreparedStatement = (OraclePreparedStatement)preparedStatement;
                        recsDeleted = oraclePreparedStatement.executeUpdate();
                        //recsDeleted = oraclePreparedStatement.sendBatch();
                   else
                        recsDeleted = preparedStatement.executeUpdate();
    catch(SQLException e)
         String err = (e.getMessage()).substring(0,e.getMessage().length()-1);
         systemClass.logSqlStatement(sqlP + " : " + err, startTime);
    throw e;
    Message was edited by:
    user539085
    Message was edited by:
    user539085
    Message was edited by:
    user539085

    user539085,
    I guess it returns 0 (zero) because it doesn't delete anything. Can you verify that it did delete some records and still returned zero?
    Good Luck,
    Avi.

  • Prepared Statements and Oracle functions:

    Consider this code:
    String searchText = "someInputText";
    StringBuffer sqlstmt = new StringBuffer();
    sqlstmt.append("SELECT ID_FIELD FROM ");
    sqlstmt.append("MY_TABLE WHERE NAME_FIELD ");
    sqlstmt.append("like INITCAP('%" + searchText + %')");
    PreparedStatement ps = con.prepareStatement(sqlstmt.toString());This works fine like this, but when I replace the searchText in the sqlstmt to ? it doesn't work:
    sqlstmt.append("like INITCAP('?')");
    PreparedStatement ps = con.prepareStatement(sqlstmt.toString());
    ps.setString(1, "%" + searchText + "%");How do you use the PreparedStatement with a
    function like INITCAP where you need to use a
    dynamic ? in the sql statement?
    Thanks,
    Rob.

    Very easy to miss this.
    Don't put the percentages IN the SQL statement.
    Append the percentages to your string.
    Like this:
    String searchText = "%" + "someInputText" + "%";
    StringBuffer sqlstmt = new StringBuffer();
    sqlstmt.append("SELECT ID_FIELD FROM ")
           .append("MY_TABLE WHERE NAME_FIELD ")
           .append("like INITCAP(?)");
    PreparedStatement ps = con.prepareStatement(sqlstmt.toString());
    ps.setString(1, searchText);
    resultSet = ps.executeQuery();Wish I saw this earlier for you.

  • Handling ' and " in a Prepared Statement

    Hi,
    I am using a prepared statement (WebLogic Portal Server having JDBC communication with MS SQL server)
    I HAVE to pass a string like '"*ABC*"'
    i.e. <single quote><double quote>*ABC<double quote><single quote>
    If i hard code this value within the prepared statement it works.
    If i try to pass it as argument it fails.
    In my case the user may submit any string value in the place of ABC
    Kindly advise
    regards
    -Ramudu

    You're probably trying to include the quotes in the prepared statement and pass the ABC as the text to substitute for the question mark. It doesn't really work like that. It's all or nothing. Create your parameter like this:
    public String quoteWrapper(final String unwrappedParameter) {
       return "'\"*"+unwrappedParameter+"*\"'";
    }

  • Query slow when executing using prepared statement compared to sqlDeveloper

    Oracle version is 10.2.0.1.0.
    I have got a query which when submitted from java code using prepared statement and parameter substitutions, takes more than 20 seconds to give results.
    I can see this SELECT sql sitting there when I run Monitor Sessions through sqlDeveloper, with its wait time increasing and then finally getting through. During that time no other SQLs are waiting.
    DURING THAT TIME then I am able to run the same query (with values included) multiple times using sqlDeveloper, and it gives results in no time.
    Sqldeveloper connects using thin client using lib provided by oracle in windows.
    Java code runs from linux and uses the thin client using lib provided by oracle in linux.
    Both are hitting the same DB running on a separate Linux machine.
    What could be the cause of this problem?
    What db parameters, queries should I run to identify the bottleneck?
    Edited by: user10390517 on Jun 14, 2010 3:06 AM

    Hi Rob,
    at least you should see some differences in the statistics for the different child cursor (the one for the execution in the application should show at least a higher value for ELAPSED_TIME). I would use something like the following query to check the information for the child cursors:
    select sql_id
         , PLAN_HASH_VALUE
         , CHILD_NUMBER
         , EXECUTIONS
         , ELAPSED_TIME
         , USER_IO_WAIT_TIME
         , CONCURRENCY_WAIT_TIME
         , DISK_READS
         , BUFFER_GETS
         , ROWS_PROCESSED
      from v$sql
    where sql_id = your_sql_idRegards
    Martin

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

  • When to use prepared statement in java?

    Hi all,
    If we have query like select * from {tablename} (Here tablename is the variable) then will the use of prepared staement improve the performance? My guess is use of statement in this case is a better option rather than prepared statement as the tablename may change for every other query.I think are not useful if tablename changes.They are useful only when the where clause has dynamic values.

    cantor wrote:
    Are you sure that your approach is possible? The next example causes exception for me.
    PreparedStatement ps = conn.prepareStatement("select * from ?");
    ps.setString(1, "TABLE_NAME");
    ps.executeQuery();
    I didn't say that he should solve it in that way. He should create one prepared statement like this "select a, b, c from tablename1" and another prepared statement when he wants to execute "select d, e, f from tablename2"
    >
    And as I understand, this code will not improve perfomance (and even will not work). As I said it can.
    Prepared statements make possible usage compiled queries inside DB. When DB gets prepared statement call, it need to parse it only once. And it can collect some statistic to improve execution plan. But when table name is not specified, this approach will not work.Yes it might. There are database drivers that can cache prepared statements and it's isn't likely that he executes that query on more than e.g. 20 tables?
    The database can also cache compiled statements in a cache.
    Kaj

  • Beginner question about prepared statements...PLEASE help! :-)

    First let me say thanks for the assistance. This is probably really easy to do, but I'm new to JSP and can't seem to figure it out.
    I want to dynamically populate a table that shows whether a particular person has an appointment at a given date and time with a user. To do this, I want to query the MySQL database for the lastname of the person with the appointment that occurs with the user at the year, month, date, and time, in question.
    THE CODE BELOW DOESN'T WORK (obviously) BUT SOMEWHAT ILLUSTRATES WHAT I'M TRYING TO ACCOMPLISH:
    <%
    Driver DriverTestRecordSet = (Driver)Class.forName(MM_website_DRIVER).newInstance();
    Connection ConnTestRecordSet = DriverManager.getConnection(MM_website_STRING,MM_website_USERNAME,MM_website_PASSWORD);
    PreparedStatement StatementTestRecordSet = ConnTestRecordSet.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id='<%=(((Recordset1_data = Recordset1.getObject(user_id))==null || Recordset1.wasNull())?"":Recordset1_data)%>' AND year='<%= yy %>' AND month='<%= months[mm] %>' AND date='<%= dates[dd] %>' AND appttime='16:15:00'");
    ResultSet TestRecordSet = StatementTestRecordSet.executeQuery();
    boolean TestRecordSet_isEmpty = !TestRecordSet.next();
    boolean TestRecordSet_hasData = !TestRecordSet_isEmpty;
    Object TestRecordSet_data;
    int TestRecordSet_numRows = 0;
    %>
    The real problem comes in the prepared statement portion. If I build the prepared statement with static values like below, EVERYTHING WORKS GREAT:
    PreparedStatement StatementTestRecordSet = ConnTestRecordSet.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id='1' AND year='2002' AND month='October' AND date='31' AND appttime='16:15:00'");
    But when I try to use dynamic values, everything falls apart. It's not that the values aren't defined, I use the user_id, year <%= yy %>, month <%= months[mm] %>, etc. elsewhere on the page with no problems. It's just that I can't figure out how to use these dynamic values within the prepared statement.
    Thanks for reading this far and thanks in advance for the help!!!!

    Hi PhineasGage
    You are little bit wrong in your
    your preparedStatement.
    Expression tag within scriptlet tag is invalid.
    Whenever you are appending the statement with
    expression tag, append it with "+" and remove
    expression tag.
    Hopefully it will work
    ThanksThanks for the response!
    I know that the expression tag within scriptlet tag is invalid. I just need a workaround for what I want to do.
    I'm unclear what you mean by "Whenever you are appending the statement with expression tag, append it with a "+" and remove expression tag".
    Could you give an example?
    In the meantime, I've been trying to digest the docs on prepared statements and have changed the code to look like:
    PreparedStatement StatementTestRecordSet = ConnTestRecordSet.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id= ? AND year= ? AND month= ? AND date= ? AND appttime='13:15:00'");
    StatementTestRecordSet.setInt(1,1);
    StatementTestRecordSet.setInt(2,2002);
    StatementTestRecordSet.setString(3,"October");
    StatementTestRecordSet.setInt(4,31);
    Again, WITH THE STATIC VALUES, THIS WORKS FINE...but when I try to use expressions or variables like below, things don't work:
    StatementTestRecordSet.setInt(2,<%= yy %>);
    Obviously, I'm doing something wrong, but there has to be a way to use variables within the prepared statement.
    ALSO, the values are being passed to this page via URL in the form:
    samplepage?user_id=1&year=2002&month=October&date=31
    Based upon this information, is there another way (outside of stored procedures in the db) to do what I want to do? I'm open to ideas.

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

Maybe you are looking for

  • Installation problem in 10g on windows vista

    my system's OS is window vista. when i installed oracle 10 g then it is install easily and also working , but after reopen the system then it(oracle 10 g) is not working. gives different type error just like "listener does not currently know of servi

  • Using Dumplog to generate CVP server log

    Hi everyone, I want to generate logs in the cvp (7.0) server using the dumplog command, can anyone advice me which process name to use, and the procedure. Severin

  • Two HP Pavilion 23fi 23-inch dead short after end of warranty!!

    Dear HP, I live in Australia and it is almost impossible to find the right information or even support from your local web site. I have two HP Pavilion 23fi 23-inch Diagonal IPS LED Backlit Monitor (C7T77A2) here on my desk and a few days apart BOTH

  • Creating a gallery with widgets

    I'm creating my portfolio website and I want to have an image that when clicked, a gallery will pop up and the viewer can look through multiple images. I've tried using composition widgets but from what I've seen, they all require having multiple tri

  • 9i Standby Database - Failover Question - REF 227196.1

    Hi , Im researching the use of a Standby DB for out Production DB.... The Metalink DOC 227196.1 mentions that in failover , the Production going down , Standby becomes Primary and cannot be come Standby again , whereas with Switchover , they can be s