PreparedStatement.setCharacterStream()  length

It seems perverse that PreparedStatement.setCharacterStream() requires the length of the character stream as a parameter. Is there a value you can feed it so it will simply read to EOF?
public void setCharacterStream(int�parameterIndex,
Reader�reader,
int�length)
throws SQLException
Sets the designated parameter to the given Reader object, which is the given number of characters long. When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
Parameters:parameterIndex - the first parameter is 1, the second is 2, ...reader - the java.io.Reader object that contains the Unicode datalength - the number of characters in the stream Throws: SQLException - if a database access error occurs

user_7000002 wrote:
We seem to be having problems inserting and retrieving the data back into UTF-8.
I am trying to insert a text with a smart quote i.e. '’' character but it doesn't seem to get written correctly and comes back as if it gets re-encoded twice to UTF-8 and comes back as the charcter ''
My oracle database encoding is WE8ISO8859P1.You have the issue right there.
If by smart quotes you are referring to the Microsoft specific curvy quotes of e.g. 125x in the "C1 control code range", then it simply won't work.
You can not store such characters in a database with a character set based on standard ISO 8859-1, because the character repertoire does not define "smart quotes". Put differently, your database needs to be "at least" WE8MSWIN1252 (or other superset).
On a side note; NLS questions and discussions have a separate forum: [Globalization Support|http://forums.oracle.com/forums/forum.jspa?forumID=50].
Edited by: orafad on Feb 13, 2009 10:00 AM

Similar Messages

  • Got AbstractMethodError with PreparedStatement.setCharacterStream

    Hi,
    I'm running WLS510SP12 NT with Oracle 5.0.6 and JDBC-Thin-Drivers, and
    i'm getting this exception when writing a character stream into a
    prepared sql-statement:
    java.rmi.RemoteException: Exception in non-transactional EJB invoke:
    java.lang.AbstractMethodError:
    weblogic/jdbc/pool/PreparedStatement.setCharacterStream
         at weblogic.jdbc20.rmi.internal.PreparedStatementImpl.setCharacterStream(PreparedStatementImpl.java:330)
         at weblogic.jdbc20.rmi.SerialPreparedStatement.setCharacterStream(SerialPreparedStatement.java:421)
         at com.mybean.add(BOFaxBean.java:970)
    Note that the Exception is not thrown in the oracle jdbc-driver, but
    in a weblogic class.
    Sourcecode:
    pstm = con.prepareStatement("INSERT INTO FAX VALUES(?,?,?,?,?,?,?)");
    pstm.setCharacterStream(3, new StringReader(sFAX.toString()),
    sFAX.length() );
    Can anybody help?
    Regards,
    Andy

    Andreas Lange wrote:
    Hi,
    I'm running WLS510SP12 NT with Oracle 5.0.6 and JDBC-Thin-Drivers, and
    i'm getting this exception when writing a character stream into a
    prepared sql-statement:
    java.rmi.RemoteException: Exception in non-transactional EJB invoke:
    java.lang.AbstractMethodError:
    weblogic/jdbc/pool/PreparedStatement.setCharacterStream
    at weblogic.jdbc20.rmi.internal.PreparedStatementImpl.setCharacterStream(PreparedStatementImpl.java:330)
    at weblogic.jdbc20.rmi.SerialPreparedStatement.setCharacterStream(SerialPreparedStatement.java:421)
    at com.mybean.add(BOFaxBean.java:970)
    Note that the Exception is not thrown in the oracle jdbc-driver, but
    in a weblogic class.That class is just catching all exceptions from the DBMS driver, and casting them to a SQLException.
    It's the Oracle driver you're using. It doesn't even know about that JDBC 2.0 call. It must be a
    JDBC 1.0 driver.
    Joe
    >
    >
    Sourcecode:
    pstm = con.prepareStatement("INSERT INTO FAX VALUES(?,?,?,?,?,?,?)");
    pstm.setCharacterStream(3, new StringReader(sFAX.toString()),
    sFAX.length() );
    Can anybody help?
    Regards,
    Andy

  • Inserting to a CLOB field in Oracle 8i  Database

    Hi All,
    I am trying to insert a value to a CLOB field in Oracle 8i DB.
    The value gets inserted when the size is less (Up to around 80 Bytes).
    When the size becomes larger the insertion does not take place but no exception is thrown.
    Please see below the code I have written.
    PreparedStatement preparedStatement = null;
              try {
                   connection = getConnection(MMAKeys.WMDS_DATASOURCE);
                   String query = "UPDATE s_mmhp_batch SET MMHP_REPORT_CLOB=(?) WHERE MMHP_BATCH_ID=(?) AND MMHP_USER_ID=(?) AND MMHP_MEMBER_KEY=(?)";
              preparedStatement=connection.prepareStatement(query);
              Reader r = new StringReader(clobReport);
              preparedStatement.setCharacterStream(1, r, clobReport.length());
              oracle.sql.CLOB newClob = oracle.sql.CLOB.createTemporary(connection , false, oracle.sql.CLOB.DURATION_CALL);
              newClob.putString(1,clobReport);
              preparedStatement.setClob(1,newClob);
              preparedStatement.setInt(2,batchId);
              preparedStatement.setString(3,userId);
              preparedStatement.setString(4,memberKey);
              preparedStatement.executeUpdate();
              System.out.println("inside the write to Batch method after executing the query");
              } catch (SQLException exception) {
                   throw new DAOException(
                        "MREDMMSDAO -> writeToTable():SQLException"
                             + exception.getMessage());
              } catch (Exception exception) {
                   throw new DAOException(
                        "MREDMMSDAO -> writeToTable():Exception"
                             + exception.getMessage());
              } finally {
                   closeStatement(preparedStatement);
                   closeConnection(connection);
    I came to know that this method is not supported in Oracle 8i.
    I tried to create an empty CLOB and call the putValue() method.
    But Then, I got an exception stating that the method is not supported.
    Is there any other way to insert a CLOB value to Oracle 8i?
    Please help.
    Thanks in advance,
    Neelambary

    And cursor.callproc('insert_clob_proc', (clob,))
    doesn't work for you?
    PrzemekYes - I should have been more clear in my original post. The callproc function works until we have a value which is over 32K. At values over 32K, we get an error message "ORA-01460: unimplemented or unreasonable conversion requested". I believe this is because we are sending the value as a string and so we would need to figure out how to send as a CLOB in cx_Oracle? Here is some code to use to test if interested...
    Oracle (Oracle Database 10g Release 10.1.0.4.0 - Production):
    CREATE TABLE clob_test (CLOB_FIELD CLOB);
    CREATE OR REPLACE PROCEDURE ins_clob_test (v_clob_field IN CLOB)
    AS
    BEGIN
    INSERT INTO clob_test (clob_field) VALUES (v_clob_field);
    END ins_clob_test;
    Python (2.5):
    conn = cx_Oracle.connect(xhash['oraclelogin'])
    cursor = conn.cursor()
    clob_var = 'Some test data' * 10000
    cursor.callproc('ins_clob_test',(clob_var,))
    conn.commit()
    cursor.close()
    conn.close()
    I should also mention that I am the Oracle developer and not the Python programmer - my knowledge of Python is very limited. I would like the Python programmers to use the procedures (packages) I have created to do their inserts but this situation has caused them to put the SQL directly in their code.
    Thanks again for any assistance you can provide.
    Jason

  • Character Encodings when using Streams for Text

    hi there,
    i have a table with a key column (ordinary varchar) and a text column (memo field in ms access, connection is done via the jdbc2odbc bridge). if i read the stuff with ResultSet.getAsciiStream() everything is fine, i.e., printing the resulting strings looks ok. then i use this method to read it and write it into a second table with the same structure but using PreparedStatement.setCharacterStream(). now i read from the second table using ResultSet.getCharacterStream() and print the strings. but now they seem garbled. something with the text conversion must have gone wrong. i never set any character encoding so the encodings should all be default.
    any ideas?
    robert

    Can you confirm that the data has been stored to the
    second table correctly?
    Ie, is it getCharacterStream or setCharacterStream
    that's causing the problems?that's difficult to answer: if i use the access interface to look into both tables they look alike. especially the target table looks ok.
    but if i read the data with getCharacterStream() i get something that looks as if this had happened: during storing with setCharacterStream() for every character there seem to be two bytes stored in the table. after reading the output looks like every second character was ok and every other character seems garbled. so it looks like on reading not two bytes in the database made a character but only one so every second byte becomes crap.
    unfortunately there is neither method in Reader that allows for setting the encoding nor is there a variant of getCharacterStream() that accepts an encoding parameter. (the same holds for setCharacterStream(); plus, if i create a StringReader there is no way to set the encoding.)
    do you have still any ideas?
    robert

  • SQLServer 2000 & JDBC

    Hi,
    I still have problems with the SQL Server 2000 drivers for JDBC.
    The documentation shows that .beforeFirst(), .absolute() and others methods are available but when i run my app, I have the error :
    [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported method: ResultSet.absolute
    Have any idea ? Please help

    Well, i'd say "shit happens". This is something not uncommon: implement an interface but don't support all of its methods. Ever got an java.util.List as a return value from some method and tried to call add() and realized that the return value was a Collections.EMPTY_LIST? Or they don't support all methods under all circumstances. The Oracle JDBC driver doesn't support PreparedStatement.setCharacterStream in combination with batch updates. It jus throws an Exception if you trie to do use it. Life just sucks .... ;-)

  • ORA-24334 error after loadSampleData

     

    Hi Stephen,
    There is a known issue with reading/writing large CLOBs and double-byte
    characters. For the Oracle jDriver in WLS 6.1 sp1 you will need to request two
    patches from WLS support ( http://www.bea.com/support/index.jsp ). Request the
    patches for CR046149 and CR060917.
    Also, verify that your Enterprise Applications use "Use CLOBs for Read" and
    "Use CLOBs for Write" = true (this is the out-of-the-box setting for the example
    apps). You set these properties in the console (http://<server>:port/console).
    For the portal application, you would navigate to Deployments --> Applications
    --> portal --> Service Configuration --> JDBC Helper Service.
    When the true settings are used the JdbcHelper will read CLOBs using
    ResultSet.getClob() and Clob.getCharacterStream(). The JdbcHelper will write
    character data to a CLOB field in the database using a
    PreparedStatement.setCharacterStream() call for the CLOB field (for the true
    setting). If the settings are false then reads are done by using
    ResultSet.getString() and writes are done with PreparedStatement.setString().
    If the patches do not solve your problem, please re-post.
    FYI, the WLCS team is working on a delegate model for the JdbcHelper that
    will allow Portal 4.0 to take advantages of database-specific extensions to the
    JDBC 2.0 spec for writing CLOBs. The JDBC 2.0 spec does not handle writing data
    to CLOBs. Notice that java.sql.Clob has only methods for reading CLOBs. These
    extensions to the specification will allow us to stream data directly to the
    CLOB instead of inserting character data into the CLOB field in the database.
    Watch the release notes for Portal 4.0 at
    http://edocs.bea.com/wlp/docs40/relnotes/index.htm for updates.
    Stephen Yau wrote:
    Hi all,
    Just download & install Portal 4.0.... take longgggg time to startup :(.
    Anyway, after I get Portal 4.0 up and running, I went thought the
    configuration for Oracle, after I ran loadSampleData.bat and restart the
    server, I got the following error:
    ####<2001/11/8 ¤W¤È12®É33¤À46¬í> <Info> <EJB> <fish-mobile> <portalServer>
    <main> <system> <> <010008> <EJB Deploying file: placeholder.jar>
    ####<2001/11/8 ¤W¤È12®É33¤À47¬í> <Info> <EJB> <fish-mobile> <portalServer>
    <main> <system> <> <010009> <EJB Deployed EJB with JNDI name
    wlcsApp.BEA_personalization.AdConflictResolver.>
    ####<2001/11/8 ¤W¤È12®É33¤À47¬í> <Info> <EJB> <fish-mobile> <portalServer>
    <main> <system> <> <010009> <EJB Deployed EJB with JNDI name
    wlcsApp.BEA_personalization.AdBucketService.>
    ####<2001/11/8 ¤W¤È12®É33¤À47¬í> <Info> <EJB> <fish-mobile> <portalServer>
    <main> <system> <> <010009> <EJB Deployed EJB with JNDI name
    wlcsApp.BEA_personalization.AdService.>
    ####<2001/11/8 ¤W¤È12®É33¤À47¬í> <Info> <EJB> <fish-mobile> <portalServer>
    <main> <system> <> <010009> <EJB Deployed EJB with JNDI name
    wlcsApp.BEA_personalization.PlaceholderService.>
    ####<2001/11/8 ¤W¤È12®É33¤À48¬í> <Info> <Data Synchronization> <fish-mobile>
    <portalServer> <main> <system> <> <000000> <Application: wlcsApp; Data
    Repository of type "Placeholder Data Repository" created with persistence
    manager of type
    "com.bea.p13n.placeholder.internal.PlaceholderPersistenceManager".>
    ####<2001/11/8 ¤W¤È12®É33¤À51¬í> <Error> <Data Synchronization>
    <fish-mobile> <portalServer> <main> <system> <> <000000> <Application:
    wlcsApp; Master Data Repository construction failed. Application data will
    not be available to services. Please see the following exception and
    restart the server.>
    Exception[com.bea.p13n.management.data.repository.PersistenceException: An
    error ocurred refreshing a Data Repositorys PersistenceManager: {0}] - with
    embedded exception:
    [Exception[com.bea.p13n.management.data.repository.PersistenceException:
    Failed to refresh JDBC Persistence Manager.] - with embedded exception:
    [java.sql.SQLException: An IOException has occurred in jdbcHelper.getClob():
    Error in getLobStringValue java.sql.SQLException: ORA-24334: ¨S¦³´yz²Åµ¹¦¹
    ¦ì¸m]]
    at
    com.bea.p13n.management.data.repository.internal.AbstractDataRepository.<ini
    t>(AbstractDataRepository.java:198)
    at
    com.bea.p13n.management.data.repository.internal.MasterDataRepository.<init>
    (MasterDataRepository.java:46)
    at
    com.bea.p13n.management.data.repository.DataRepositoryFactory.getMasterDataR
    epository(DataRepositoryFactory.java:255)
    at
    com.bea.p13n.placeholder.internal.PlaceholderServiceImpl.ejbCreate(Placehold
    erServiceImpl.java:191)
    at
    com.bea.p13n.placeholder.internal.PlaceholderServiceImpl_9p0jz2_Impl.ejbCrea
    te(PlaceholderServiceImpl_9p0jz2_Impl.java:112)
    at java.lang.reflect.Method.invoke(Native Method)
    at
    weblogic.ejb20.pool.StatelessSessionPool.createBean(StatelessSessionPool.jav
    a:153)
    at weblogic.ejb20.pool.Pool.createInitialBeans(Pool.java:191)
    at weblogic.ejb20.pool.Pool.onAfterDeploy(Pool.java:172)
    at
    weblogic.ejb20.deployer.Deployer.runAfterDeploymentListeners(Deployer.java:1
    317)
    at weblogic.ejb20.deployer.Deployer.deploy(Deployer.java:1005)
    at weblogic.j2ee.EJBComponent.deploy(EJBComponent.java:30)
    at weblogic.j2ee.Application.addComponent(Application.java:160)
    at weblogic.j2ee.J2EEService.addDeployment(J2EEService.java:117)
    at
    weblogic.management.mbeans.custom.DeploymentTarget.addDeployment(DeploymentT
    arget.java:329)
    at
    weblogic.management.mbeans.custom.DeploymentTarget.addDeployments(Deployment
    Target.java:279)
    at
    weblogic.management.mbeans.custom.DeploymentTarget.updateServerDeployments(D
    eploymentTarget.java:233)
    at
    weblogic.management.mbeans.custom.DeploymentTarget.updateDeployments(Deploym
    entTarget.java:193)
    at java.lang.reflect.Method.invoke(Native Method)
    at
    weblogic.management.internal.DynamicMBeanImpl.invokeLocally(DynamicMBeanImpl
    .java:608)
    at
    weblogic.management.internal.DynamicMBeanImpl.invoke(DynamicMBeanImpl.java:5
    92)
    at
    weblogic.management.internal.ConfigurationMBeanImpl.invoke(ConfigurationMBea
    nImpl.java:352)
    at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
    at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
    at weblogic.management.internal.MBeanProxy.invoke(MBeanProxy.java:449)
    at weblogic.management.internal.MBeanProxy.invoke(MBeanProxy.java:190)
    at $Proxy40.updateDeployments(Unknown Source)
    at
    weblogic.management.configuration.ServerMBean_CachingStub.updateDeployments(
    ServerMBean_CachingStub.java:2734)
    at
    weblogic.management.mbeans.custom.ApplicationManager.startConfigManager(Appl
    icationManager.java:362)
    at
    weblogic.management.mbeans.custom.ApplicationManager.start(ApplicationManage
    r.java:154)
    at java.lang.reflect.Method.invoke(Native Method)
    at
    weblogic.management.internal.DynamicMBeanImpl.invokeLocally(DynamicMBeanImpl
    .java:608)
    at
    weblogic.management.internal.DynamicMBeanImpl.invoke(DynamicMBeanImpl.java:5
    92)
    at
    weblogic.management.internal.ConfigurationMBeanImpl.invoke(ConfigurationMBea
    nImpl.java:352)
    at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
    at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
    at weblogic.management.internal.MBeanProxy.invoke(MBeanProxy.java:449)
    at weblogic.management.internal.MBeanProxy.invoke(MBeanProxy.java:190)
    at $Proxy56.start(Unknown Source)
    at
    weblogic.management.configuration.ApplicationManagerMBean_CachingStub.start(
    ApplicationManagerMBean_CachingStub.java:480)
    at weblogic.management.Admin.startApplicationManager(Admin.java:1151)
    at weblogic.management.Admin.finish(Admin.java:570)
    at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java:506)
    at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:203)
    at weblogic.Server.main(Server.java:35)
    Here is the description for ORA-24334:
    ORA-24334: no descriptor for this position
    Cause: The application is trying to get a descriptor from a handle for an
    illegal position.
    Action: Check the position number.
    The loadSampleData.bat ran fine and didn't report any error. NLS setting
    is ZHT16BIG5.
    Anyone have any idea?
    -Stephen Yau--
    Ture Hoefner
    BEA Systems, Inc.
    2590 Pearl St.
    Suite 110
    Boulder, CO 80302
    www.bea.com

  • Setting a null(empty) binary stream in a PreparedStatement

    How can I bind a null binary stream into a PreparedStatement?
    In the following, if pMap is null how do I bind it? If I try to serialize a null pMap I get and error that not all columns bound.
    if(pMap == null)
    else
    byte[] _bytes = SerializeUtility.serializeObject(pMap);
    pStatement.setBinaryStream(pColCount, new ByteArrayInputStream(_bytes), _bytes.length);
    Thanks,
    David

    I was too close to the monitor, couldn't see the big picture ! :-) Now it works.
    Although, I still get that Websphere error:
    7c7fc721 SharedPool I J2CA0086W: Shareable connection MCWrapper id 31c73d Managed connection comm.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl@2e55c73d State:STATE_TRAN_WRAPPER_INUSE from resource jdbc/ds was used within a local transaction containment boundary.
    It use to work fine, no errors.
    Any ideeas??
    mihut

  • PreparedStatement and empty String instead of space

    Hi all, I would test a space value in a varchar field, i.e.:
    PreparedStatement ps=con.prepareStatement();
    String qry = "select a from table where b=? and c=?";
    ps.setString(1,"value");
    ps.setString(2," "); // space!!
    That source code doesn't work: it set "" (empty String) in the second field, not " " (space).
    Can I use PrepareStatement in any way to do this or I have to use only Statement?
    Thanks.
    Bye.

    my friend, the question was: how do you know the
    parameter is set to "" (empty string)?I don't know: I suppose!!! because it's the only reason for that it returns no record. I tested my query in this three ways:
    1) directly in sqlplus: SELECT OCCFASE As fase, OCLCVVC as convRat, SUM(QTA1) As qta1UM, SUM(QTA2) As qta2UM
    FROM DJITMPRE WHERE OCCFASE IN ('I','P') AND OCCCOSC='XXXXX' AND OCCITEM='RUG-02' AND OCCTPVR = 'RUG'
    AND OCCVAR1 = '01' AND OCCVAR2 = 'WW' AND OCCVAR3 = '12' AND OCCTPIM = '01' AND MAGAZZINO = 'MAG03'
    AND COMMESSA = ' ' AND ORIG = ' ' AND PARTITA = ' ' AND CONFIG = 0.0 AND VANO = ' '
    GROUP BY OCCFASE, OCLCVVC
    and it returns one record.
    2) using Statement:
         Statement s = conn.createStatement();
         String societa=session.getCompanyLogisticName(DSession.TABLE_LOGISTIC);
              StringBuffer qry=new StringBuffer();
              StringBuffer whereClause=new StringBuffer();
              qry.append("SELECT OCCFASE As fase, OCLCVVC as convRat, SUM(QTA1) As qta1UM, SUM(QTA2) As qta2UM ");
              qry.append("FROM DJITMPRE ");
              qry.append("WHERE OCCFASE IN ('I','P') ");
              qry.append("AND OCCCOSC='");
              qry.append(societa);
              qry.append("' ");     
              whereClause.append("AND OCCITEM='");
              whereClause.append(b.getItemCode());
              whereClause.append("' ");
              whereClause.append("AND OCCTPVR = '");
         if (b.getVariantType().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getVariantType(), 1));
         }else{
              whereClause.append(b.getVariantType());
         whereClause.append("' ");
         whereClause.append("AND OCCVAR1 = '");
         if (b.getFirstVariant().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getFirstVariant(), 1));
         }else{
              whereClause.append(b.getFirstVariant());
         whereClause.append("' ");
         whereClause.append("AND OCCVAR2 = '");
         if (b.getSecondVariant().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getSecondVariant(), 1));
         }else{
              whereClause.append(b.getSecondVariant());
         whereClause.append("' ");
         whereClause.append("AND OCCVAR3 = '");
         if (b.getThirdVariant().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getThirdVariant(), 1));
         }else{
              whereClause.append(b.getThirdVariant());
         whereClause.append("' ");
         whereClause.append("AND OCCTPIM = '");
         if (b.getPackingType().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getPackingType(), 1));
         }else{
              whereClause.append(b.getPackingType());
         whereClause.append("' ");
         whereClause.append("AND MAGAZZINO = '");
         if (b.getWarehouseCode().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getWarehouseCode(), 1));
         }else{
              whereClause.append(b.getWarehouseCode());
         whereClause.append("' ");
         whereClause.append("AND COMMESSA = '");
         if (b.getProjectItem().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getProjectItem(), 1));
         }else{
              whereClause.append(b.getProjectItem());
         whereClause.append("' ");
         whereClause.append("AND ORIG = '");
         if (b.getSourceLot().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getSourceLot(), 1));
         }else{
              whereClause.append(b.getSourceLot());
         whereClause.append("' ");
         whereClause.append("AND PARTITA = '");
         if (b.getLotNumber().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getLotNumber(), 1));
         }else{
              whereClause.append(b.getLotNumber());
         whereClause.append("' ");
         whereClause.append("AND CONFIG = ");
         whereClause.append(b.getItemConfiguration());
         whereClause.append("AND VANO = '");
         if (b.getLocation().equals("")){
              whereClause.append(EscapeString.getLengthString(b.getLocation(), 1));
         }else{
              whereClause.append(b.getLocation());
         whereClause.append("' ");
         qry.append(whereClause.toString());
         qry.append(" GROUP BY OCCFASE, OCLCVVC");
    ResultSet rs = s.executeQuery(qry.toString());
    and it returns one record.
    3) using PreparedStatement:
    StringBuffer qry=new StringBuffer();
    qry.append("SELECT OCCFASE As fase, OCLCVVC as convRat, SUM(QTA1) As qta1UM, SUM(QTA2) As qta2UM ");
                   qry.append("FROM DJITMPRE WHERE OCCFASE IN ('I','P') ");
                   qry.append("AND OCCCOSC='").append(societa).append("' ");
                   qry.append("AND OCCITEM=? AND OCCTPVR = ? ");
              qry.append("AND OCCVAR1 = ? AND OCCVAR2 = ? AND OCCVAR3 = ? ");
              qry.append("AND OCCTPIM = ? AND MAGAZZINO = ? AND COMMESSA = ? ");
              qry.append("AND ORIG = ? AND PARTITA = ? AND CONFIG = ? ");
              qry.append("AND VANO = ? ");
              qry.append("GROUP BY OCCFASE, OCLCVVC");
    PreparedStatement bookedQtyPS = conn.prepareStatement(qry.toString());
    bookedQtyPS.setString(1,b.getItemCode());
         if (b.getVariantType().equals("")){
              bookedQtyPS.setString(2,EscapeString.getLengthString(b.getVariantType(), 1));
         }else{
              bookedQtyPS.setString(2,b.getVariantType());
         if (b.getFirstVariant().equals("")){
              bookedQtyPS.setString(3,EscapeString.getLengthString(b.getFirstVariant(), 1));
         }else{
              bookedQtyPS.setString(3,b.getFirstVariant());
         if (b.getSecondVariant().equals("")){
              bookedQtyPS.setString(4,EscapeString.getLengthString(b.getSecondVariant(), 1));
         }else{
              bookedQtyPS.setString(4,b.getSecondVariant());
         if (b.getThirdVariant().equals("")){
              bookedQtyPS.setString(5,EscapeString.getLengthString(b.getThirdVariant(), 1));
         }else{
              bookedQtyPS.setString(5,b.getThirdVariant());
         if (b.getPackingType().equals("")){
              bookedQtyPS.setString(6,EscapeString.getLengthString(b.getPackingType(), 1));
         }else{
              bookedQtyPS.setString(6,b.getPackingType());
         if (b.getWarehouseCode().equals("")){
              bookedQtyPS.setString(7,EscapeString.getLengthString(b.getWarehouseCode(), 1));
         }else{
              bookedQtyPS.setString(7,b.getWarehouseCode());
    //cat.debug("b.getProjectItem(): "+b.getProjectItem());
         if (b.getProjectItem().equals("")){
              //cat.debug("entro in 1 b.getProjectItem().length: "+b.getProjectItem().length());
              bookedQtyPS.setString(8,EscapeString.getLengthString(b.getProjectItem(), 1));
              //bookedQtyPS.setString(8," ");
         }else{
              //cat.debug("entro in 2 b.getProjectItem().length: "+b.getProjectItem().length());
              bookedQtyPS.setString(8,b.getProjectItem());
         bookedQtyPS.setString(8," ");
    //cat.debug("b.getSourceLot(): "+b.getSourceLot());     
         if (b.getSourceLot().equals("")){
              bookedQtyPS.setString(9,EscapeString.getLengthString(b.getSourceLot(), 1));
         }else{
              bookedQtyPS.setString(9,b.getSourceLot());
         bookedQtyPS.setString(9," ");
    //cat.debug("b.getLotNumber(): "+b.getLotNumber());     
         if (b.getLotNumber().equals("")){
              bookedQtyPS.setString(10,EscapeString.getLengthString(b.getLotNumber(), 1));
         }else{
              bookedQtyPS.setString(10,b.getLotNumber());
         bookedQtyPS.setString(10," ");
    //cat.debug("b.getItemConfiguration(): "+b.getItemConfiguration());
         bookedQtyPS.setString(11,""+b.getItemConfiguration());
    //cat.debug("b.getLocation(): "+b.getLocation());     
         if (b.getLocation().equals("")){
              bookedQtyPS.setString(12,EscapeString.getLengthString(b.getLocation(), 1));
         }else{
              bookedQtyPS.setString(12,b.getLocation());
         bookedQtyPS.setString(12," ");
    ResultSet rs = bookedQtyPS.executeQuery();
    and it returns 0 records.
    I hope I explained it well.

  • How to get the length of a field value, not the length of DB's CHAR(20)

    Hello.
    I'm trying to handle a String from my DataBase and get its length:
    String myName;
    int i;
    PreparedStatement sql = Conn.prepareStatement("SELECT NAME FROM MY_TABLE");
    ResultSet results = sql.executeQuery();
    results.next();
    myName = results.getString("NAME");
    i = myName.length();
    out.println("The value is " + myName + " and the length is " + String.valueOf(i) );
    I get:
    " The value is Tom and the lengh is 20 "
    20 is the length of the field (it's a CHAR (20) ), but I would like to get the length
    of 'Tom'.
    On other hand, I would like to detect if this value is 'Tom' or not, but trying with:
    if (myName.equals("Tom")) {...}
    or
    if (myName == "Tom") {...}
    There is no response.
    Any experience?

    myName = results.getString("NAME");
    if(myName!=null) myName = myName.trim(); //Take out trailing spaces
    i = myName.length();Sudha

  • AbstractMethodError while calling PreparedStatement.setBinaryStream()

    I am getting AbstractMethodError while calling PreparedStatement.setBinaryStream(int, InputStream) for a BLOB column
    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit
    JDBC Driver ojdbc6.jar (downloaded from oracle website corresponding to 11.2.0.2 version)
    JDK 6
    I understand this error is due to my code calling abstract method which is not available in JDBC 3.x and it requires JDBC 4.0
    But I am not able to find any traces of usage of earlier version of driver.
    Debugging steps performed with results are as below
    1) I enabled -verbose:class VM argument that outputs all the classes loaded along with jar from which it loads. Everywhere i see ojdbc6.jar (No reference to older or any other jdbc driver jar file)
    2) Below is code segment and its output
    Connection con = getConnection(); // get connection
    DatabaseMetaData d= con.getMetaData();
    d.getDatabaseProductName(); // output: Oracle
    d.getDatabaseProductVersion(); // output: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    d.getDatabaseMajorVersion(); // output: 11
    d.getDatabaseMinorVersion(); // output: 2
    d.getDriverName(); // output: Oracle JDBC driver
    d.getDriverVersion(); // output: 11.2.0.2.0
    d.getDriverMajorVersion(); // output: 11
    d.getDriverMinorVersion(); // output: 2
    d.supportsGetGeneratedKeys(); // output: true
    3) I updated code (its third party component, so not suppose to update :( )
    Added third argument whick works fine (it means at runtime it is using older jdbc driver???)
    PreparedStatement.setBinaryStream(int, InputStream, (int)length
    Please let me know if i am missing anything here... how can i solve this issue?
    Thanks!

    From my initial post
    I am getting AbstractMethodError while calling PreparedStatement.setBinaryStream(int, InputStream) for a BLOB column
    3) I updated code (its third party component, so not suppose to update )
    Added third argument whick works fine (it means at runtime it is using older jdbc driver???)(3) will not work if correct ojdbc6.jar is used. Because third argument is int and not long. long will work with ojdbc6 but will not work with older version.
    I am using third party component and they are using - PreparedStatement.setBinaryStream(int, InputStream)
    It should work with JDK 6, Oracle 11g and ojdbc6.jar driver.
    I am sure its simple classpath issue or some configuration mismatch - just couldn't see it right now.
    I will probably create new workspace / or test on other system now
    Thanks!

  • Using PreparedStatement.setString() on AS/400 VARGRAPHIC field not working

    Hello,
    I have a database table on an AS/400 that contains a VARGRAPHIC field of length 254. According to all the docs that I've read, I should be able to use PreparedStatement.setString() to set a parameter for that field. However, I never get any rows back when I execute the query. If I run the same query on the AS/400 using strsql, the query runs fine and returns the expected results. Anyone have any ideas?
    Thanks

    The Toolbox driver. In that case you might be better off asking this question in a forum that specializes in that. Go here:
    http://www-124.ibm.com/developerworks/oss/jt400/
    You will find a FAQ section, a mailing list you can subscribe to for discussions such as your question, a bug report page where you may be able to see if your question has already been reported as a bug, and so on.
    I haven't used VARGRAPHICS fields so I have no insight into your problem, except that setting graphics data from a String sounds kind of fishy to me. Good luck.

  • PreparedStatement for SQL using IN (SQL Server 2000)

    Hi, guys
    How can I create a preparedStatement for a query using IN operator, which allow me to insert any number of parameters?
    eg: SELECT * FROM Students WHERE lastname IN (?, ?, ?, ....)
    Thanks
    jacklty

    Hi, I have found a simpler way of doing this.
    private static final String QUERYSTRING = "SELECT * from junk_table "+
                                            " WHERE status in (:x) " ;
    <..somewhere later in the code...>
    StringBuffer tempBuffer=new StringBuffer(QUERYSTRING);
    //Find :1 and replace with a comma separeted list of stauts
    tempBuffer.replace(tempBuffer.indexOf(":x"),tempBuffer.indexOf(":x") + ":x".length(),
    new String(System.getProperty("status")));
    In short, here I am creating my own bind parameters named as :x,:y (lack of imagination on my part...) and then replacing the values of those values with the comma-separated value before actually creating the PreparedStatement.
    Hope this works
    --Ved                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • String length limitation on setString() in prepared statement

    Hi,
    Is any body aware of the length of string that can be passed to setString() method of prepared statement. I am getting an error "Data size bigger than max size for this type" if the string length is more than 2000 chars. I am using jdk 1.2.2 for running the application.
    Thanks in advance.
    Nihar.

    Please use the following method. It worked for me.
    PreparedStatement pstmt = ......;
    String str = .....;
    pstmt.setObject(index,str,java.sql.Types.LONGVARCHAR);
    Ranjan.

  • Querying CHAR columns with character length semantics unreliable

    Hi again,
    It appears that there is a bug in the JDBC drivers whereby it is highly unlikely that the values of CHAR columns that use character length semantics can be accurately queried using ResultSet.getString(). Instead, the drivers return the value padded with space (0x#20) characters out to a number of bytes equal to the number of characters multiplied by 4. The number of bytes varies depending on the number and size of any non-ascii characters stored in the column.
    For instance, if I have a CHAR(1) column, a value of 'a' will return 'a ' (4 characters/bytes are returned), a value of '\u00E0' will return '\u00E0 ' (3 characters / 4 bytes), and a value of '\uE000' will return '\uE000 ' (2 characters / 4 bytes).
    I'm currently using version 9.2.0.3 of the standalone drivers (ojdbc.jar) with JDK 1.4.1_04 on Redhat Linux 9, connecting to Oracle 9.2.0.2.0 running on Solaris.
    The following sample code can be used to demonstrate the problem (where the DDL at the top of the file must be executed first):
    import java.sql.*;
    import java.util.*;
    This sample generates another bug in the Oracle JDBC drivers where it is not
    possible to query the values of CHAR columns that use character length semantics
    and are NOT full of non-ascii characters. The inclusion of the VARCHAR2 column
    is just a control.
    CREATE TABLE TMP2
    TMP_ID NUMBER(10) NOT NULL PRIMARY KEY,
    TMP_CHAR CHAR(10 CHAR),
    TMP_VCHAR VARCHAR2(10 CHAR)
    public class ClsCharSelection
    private static String createString(char character, int length)
    char characters[] = new char[length];
    Arrays.fill(characters, character);
    return new String(characters);
    } // private static String createString(char, int)
    private static void insertRow(PreparedStatement ps,
    int key, char character)
    throws SQLException
    ps.setInt(1, key);
    ps.setString(2, createString(character, 10));
    ps.setString(3, createString(character, 10));
    ps.executeUpdate();
    } // private static String insertRow(PreparedStatement, int, char)
    private static void analyseResults(PreparedStatement ps, int key)
    throws SQLException
    ps.setInt(1, key);
    ResultSet results = ps.executeQuery();
    results.next();
    String tmpChar = results.getString(1);
    String tmpVChar = results.getString(2);
    System.out.println(key + ", " + tmpChar.length() + ", '" + tmpChar + "'");
    System.out.println(key + ", " + tmpVChar.length() + ", '" + tmpVChar + "'");
    results.close();
    } // private static void analyseResults(PreparedStatement, int)
    public static void main(String argv[])
    throws Exception
    Driver driver = (Driver)Class.forName(
    "oracle.jdbc.driver.OracleDriver").newInstance();
    DriverManager.registerDriver(driver);
    Connection connection = DriverManager.getConnection(
    argv[0], argv[1], argv[2]);
    PreparedStatement ps = null;
    try
    ps = connection.prepareStatement(
    "DELETE FROM tmp2");
    ps.executeUpdate();
    ps.close();
    ps = connection.prepareStatement(
    "INSERT INTO tmp2 ( tmp_id, tmp_char, tmp_vchar " +
    ") VALUES ( ?, ?, ? )");
    insertRow(ps, 1, 'a');
    insertRow(ps, 2, '\u00E0');
    insertRow(ps, 3, '\uE000');
    ps.close();
    ps = connection.prepareStatement(
    "SELECT tmp_char, tmp_vchar FROM tmp2 WHERE tmp_id = ?");
    analyseResults(ps, 1);
    analyseResults(ps, 2);
    analyseResults(ps, 3);
    ps.close();
    connection.commit();
    catch (SQLException e)
    e.printStackTrace();
    connection.close();
    } // public static void main(String[])
    } // public class ClsColumnInsertion

    FYI, this has been mentioned as early as November last year:
    String with length 1 became 4 when nls_lang_semantics=CHAR
    and was also brought up in Feburary:
    JDBC thin driver pads CHAR col to byte size when NLS_LENGTH_SEMANTICS=CHAR

  • Oracle 10G Java PreparedStatement.setString problem

    I am using jboss application server on a windows XP operating system. I installed Oracle 10G production release and am using the jdk 1.4.2.
    When I do a preparedStatment.setString method call to bind the code it does not appear to be binding the variable correctly. I don't get any exceptions it just returns nothing in the resultset. It's like it's binding it but not correctly so it distorts the query results.
    I read the 10G known bug list and found something stating this:
    * If the database character set is AL32UTF8, you may see errors
    under the following circumstances:
    - accessing LONG and VARCHAR2 datatypes.
    - binding data with setString() and setCharacterStream().
    I then tried preparedStatement.setInt to see if this worked and it does without a problem. It appears to be the setString method. I then tried doign a workaround and using setObject instead. Also does not work. I checked the database character set and it appears I have this:
    NLS_CHARACTERSET
    WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET
    AL16UTF16
    I'm very confused as this is a big problem if I can't use the setString to bind. Has anyone else found this to be the case. Any workarounds or advice for fixing?
    Thanks in advance!
    L

    Character interpretation is up to the client- as long as the database character set can handle a specific character, the client software is responsible for accepting '<char code>' from the database and rendering it as the proper '<char>'. If the client doesn't know the code point '<char code>' you get the inverted question mark.
    Are you running the WE (Western European) charset or did you install the Universal one? A quick way to check that is to do a control file trace backup and check the create controlfile SQL generated ...
    $ sqlplus /nolog;
    show parameter user_dump;
    ... --- s.b. ...admin/XE/udump
    alter database backup controlfile to trace;
    And check the ...udump directory, view the latest .trc file- CREATE CONTROLFILE ... ; if its universal should be:
    CHARACTER SET AL32UTF8
    ;

Maybe you are looking for