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

Similar Messages

  • Oracle Prepared Statement - 8.1.7 JDBC type II Driver

    Hi,
    I have a strange problem.
    I do a query using a prepared statement and there are no matching results.
    I change this to hardcoded SQL Statement and pass in the same value a row of record is returned
    I change this to Statement and pass in the input a row of record is returned.
    This is puzzling. There seems to be a problem with Prepared Statement and I can't see why that fails.
    The Stmt looks like this
    PreparedStatement id is defiend as a char in the database
    Code Snippet:
    SQL = Select * from employee where id = ?;
    pstmt.setString(1,'value');
    Hardcoded SQL:
    select * from employee where id = 'value';
    Statement Impl:
    String var = "value";
    "select * from employee where id = '" + var+ "'";
    Would appreciate if somebody can explain what's happening. To me it is bizarre!
    Thanks,
    Manglu

    Update to problem
    I have the latest (classes12.zip) JDBC drivers from Oracle.
    We are running Oracle 8.1.6 and converting to Oracle 8.1.7.
    This works the same with both.
    Example, I have a column (char(10)) with trailing spaces. i.e. '39 '.
    When I perform a Prepared Statement with that column in the where clause, it returns no result rows.
    When I perform a standard statement with that column in the where clause, it returns rows.
    When I define a column char(2) and use it in the where clause it works fine.
    When I define a column varchar2(10) and load it with data like '39', it works fine.
    When I define a column varchar2(10 and load it with data like '39 ', it does not work.
    When I execute this same Prepared Statement through the jdbc:odbc bridge it works fine.
    I cannot change the definition of the columns as they are foreign key data. What is the problem here? Any help is appreciated.
    If you need further information please feel free to contact me.

  • 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

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

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

  • 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

  • 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

  • Removing Commas and Spaces from Field

    I have a table called TableD1 in a database with a field called "Range".
    The ranges are like 1-1000; 1001-2000; etc. up to like 1000000-200000.
    That is how they are supposed to look, they are not numeric fields, just general, containing a low, a dash and a high all in the same field.
    I just discovered that quite a few of the entries have included commas and spaces, like 1-1,000 or 100000 - 200000.
    I need to write a Query that will remove all of the commas from the data in TableD1's "Range" field, then all of the spaces.
    I imagine they are some kind of Update statements but because of the potential to blow up the whole thing, I'm reluctant to experiment.
    Does anyone know what code I should use?
    Thank you in advance for any help.
    Gee

    Making sure you've taken a backup. Pull the data into temp table and do the testing. once you satisfied with the output then do the update on the main table.
    create table #temp
    Range varchar(100)
    insert into #temp values('1-1,000'),('100000 - 200000')
    select replace(replace(Range,',',''),' ','') from #temp
    --update #temp set Range=replace(replace(Range,',',''),' ','')
    Validate the the output of the select statement.
    --Prashanth

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

  • Problem with Oracle Prepared Statement

    Hi all,
    Please help me..
    I Have 2 pages, in first page i had table with rows with update image for each row, when i click update it leads to 2nd page which shows the particular row information
    my problem is, i am executing prepared statement with 2 parameters in 2nd page controller which is working fine first time, when i go to first page and comes to 2nd page again my
    result set showing Null, some times query executing and getting results, some times null, i am confused with this behaviour. please help me ..
    Thanks all

    Hi ,
    How your table is being popluated ? You have executed VO in PR or PFR ?
    Please give snippet of your CO code , both after navigating from first page to second and again after coming back to first page .
    Also is same AM is retain or not ?

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

  • Reduce field size and space between fields

    Is there any trick to reduce the size of a field more than "normal" and the space between fields?
    I'm creating a form that looks like at table of 5 rows and 8 columns.
    Some of the fields is with list function, and they in special take more space than other fields.
    When changing the form layout in the web browser I could move the "listfields" to different places and suddenly I can for example reduce them from 124 to 114 that is the smallest I have seen them. Also if try to reduce the same field later it just pops up from 114 to 139.
    The space between fields is also annoying large when I try to keep this form as small as possible.
    Why am I asking for this?
    I know I can increase the size of the form, but I want it as small as possible for the smartphones.
    The "listfields only contains number from 1 to 9, so they can be very small.

    Hi,
    We currently have minimum widths defined for each field type. It shouldn't be possible to reduce the size of a field below that minimum width. If possible, could you please share your form with me ([email protected]) to allow me to investigate the behavior that you are seeing with your "listfields"? Also, could you describe how you were moving fields when you saw the field width reduce from 124px to 114px?
    Instructions for sharing a form can be found here - http://forums.adobe.com/docs/DOC-2462.
    Currently the spacing between fields cannot be modified.
    Regards,
    Brian

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

  • Oracle Describe Statement and CGI

    Hello,
    First of all,
    I would like to thank everyone that helped me out. It really
    made my much easier.
    Second,
    General Question.
    describe command in Oracle will display a specified table's
    definition.
    Now, I have a CGI program that will execute any SQL statement
    that has to do with tables on Oracle Database.
    i.e. select , update, insert, delete. Now when I tried
    describe student, i got an error (in httpd error log file:
    "invalid SQL statement". why?
    here is a code from my program,
    assuming: $fields{'sqlString'} = describe student
    $sth = $dbh->prepare($fields{'sqlString'})
    $sth->execute;
    Thanks Alex
    null

    Matt Surico (guest) wrote:
    : Alex Korneyev (guest) wrote:
    : {snip}
    : : General Question.
    : : describe command in Oracle will display a specified table's
    : : definition.
    : : Now, I have a CGI program that will execute any SQL
    statement
    : : that has to do with tables on Oracle Database.
    : : i.e. select , update, insert, delete. Now when I tried
    : : describe student, i got an error (in httpd error log file:
    : : "invalid SQL statement". why?
    : : here is a code from my program,
    : : assuming: $fields{'sqlString'} = describe student
    : : $sth = $dbh->prepare($fields{'sqlString'})
    : : $sth->execute;
    : : Thanks Alex
    : "describe" is a SQL*Plus command, not a SQL command. Other
    : SQL*Plus commands are column, spool, ttitle, etc...
    : If the Oracle user by which you execute the CGI above has
    access
    : to the data dictionary, you can issue the following command:
    : SELECT column_name, nullable, data_type, data_length
    : FROM dba_tab_columns
    : WHERE table_name = 'STUDENT'
    : AND owner = '{fill in the owner name in CAPS}'
    : If the Oracle user in your CGI doesn't have full access to the
    : data dictionary, you or the DBA could minimally grant SELECT on
    : DBA_TAB_COLUMNS to that user.
    : Hope that helps!
    : Matt Surico
    : Oracle 7.3 Certified DBA
    Thanks, that helps.
    Speaking of permissions. How do i set permissions for a user?
    acctually add user? for testing my CGI i am using orcl database
    with scott/tiger permissions. How do i view user's permissions?
    Also, I have this weird problem. Well I know the anser to it,
    but i need a way to go around it. Here it goes.
    Assuming following:
    alextable = (fname char (20), lname char(20))
    If I do the following from within SQL/Plus
    insert into alextable values('Alex','Was Here');
    then select * from alextable, i can see it. BUT if i do the same
    thing from CGI, I won't see, until i quit SQL/Plus. But if i
    issue the same command from CGI script and then do "select"
    statement, I will see the changes from SQL/Plus and CGI levels.
    I know that some databases use that as a "Rollback" feature.
    Is ther anyway to modify, maybe user permissions, or something
    else,so i would be able to see changes right away, no matter
    where i make them.
    thanks
    alex
    null

  • Oracle 11g stats and SQL plan mgt

    Oracle 11.0.1.7:
    - According to what I have read so far in the various documents it looks like when dbms gather stats run and if that results in new sql plan oracle will not automatically start using that plan until it's verified by sql tuning advisor or is evolved. Is that correct? Is that the default behaviour?
    - I just upgraded from 10g to 11g so I am not sure how stats is behaving currently. I am really concerned and want to understand how it's behaving.
    - How can I tell what's going on currently in the system in terms of stats gathering and if the new better plan is being used or not.

    You have the default setting for the two parameters in place. That means, that if SQL Plan Baselines exist, they will be used, thereby preventing new execution plans from getting used without evolvement
    optimizer_use_sql_plan_baselines=true does that.
    But by default, there are no SQL Plan Baselines as long as you don't create them - for example with the setting of
    optimizer_capture_sql_plan_baselines=trueYou can check whether SQL Plan Baselines exist with
    select * from dba_sql_plan_baselines;It should return no rows.

Maybe you are looking for