JDBC thin driver pads CHAR col to byte size when NLS_LENGTH_SEMANTICS=CHAR

We're using an Oracle 9.2 database with the database character set specified as AL32UTF8 with NLS_LENGTH_SEMANTICS set to CHAR. I've reproduced this problem with both the "classes12.zip" and "ojdbc14.jar" available with the Oracle 9.2 client installation.
The problem occurs with the JDBC thin driver. The problem does not occur with the JDBC OCI driver (nor SQL*Plus 9.2).
There are 2 relatively simply workarounds: use the OCI driver or convert CHAR columns to VARCHAR2 columns. I'm mostly curious as to whether there is some kind of setting for the thin driver to circumvent this problem, or if this is actually expected behavior. We're not that familiar with the NLS_LENGTH_SEMANTICS setting.
Consider a table as follows:
create table my_table (status CHAR(1));
If I describe the table it correctly shows the column using CHAR semantics.
STATUS CHAR(1 CHAR)
Given the AL32UTF8, this means that 4 bytes of storage are reserved for this column.
If I insert a single ASCII character in this table (for example "A") then read it back using the JDBC thin driver, I get the string "A " - the letter A followed by 3 spaces. In other words, the thin driver appears to have padded the value to its BYTE length. The OCI driver and SQL*Plus do not pad the value.
I understand that CHAR columns are normally blank padded when the data size is shorter than the defined column length, but I think that with NLS_LENGTH_SEMANTICS=CHAR, the padding should be based on the length of the column in chars, not in bytes.
Can anyone shed some light on this issue?
Thanks in advance,
Tim

Update:
I guess I should mention we're using Java 2 SDK 1.4.1_01 on Windows XP with an Oracle 9.2 database on Windows 2000.

Similar Messages

  • How does Oracle JDBC thin driver handle numbers via getString?

    Hi,
    I have a query regarding how numbers are handled by the oracle jdbc thin driver. The issue I am facing is with regards to the decimal separator (. is en_US and , in pt_BR)
    e.g. Consider the below code,
    Connection conn = DriverManager.getConnection(...);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select value from test_table1");
    while (rset.next())
    System.out.println (rset.getString(1));
    test_table1 has a single column of sql type 'number' with a single row having value "123.45"
    NLS_NUMERIC_CHARACTERS = ".,"
    Database version = 10.2.0.2.0
    There is a (generic) method to which a ResultSet is passed and it returns a dictionary of key value pairs. All column values from the ResultSet are retrieved using getString method of ResultSet.
    My question is whether the jdbc driver formats numbers (based on the locale) before returning it as a string as part of the getString method?
    e.g.
    java -Duser.language=pt -Duser.region=BR TestJDBC
    prints "123.45" and not "124,45"
    Is there a reason why getString always retrieves a number column value with '.' as the decimal separator?
    To help make things a bit more clear, all the column values retrieved are then converted into an XML (and hence the conversion to string)
    At present, the only way I see out of this is to handle numbers differently.
    i.e. something similar to,
    if (resultsetmetadata.getcolumntype .. = double OR float OR int OR long.. )
    NumberFormat.getInstance().format(rset.getDouble(1));
    Is there a better way to resolve this issue?
    Thanks,
    Binoy

    user565580,
    As has been already stated, Oracle does not have data-types INTEGER or SMALLINT, only NUMBER.
    So even though Oracle lets you write INTEGER, it really creates a NUMBER.
    (As Joe mentioned.)
    Other databases don't have a NUMBER data-type, they have INTEGER, SMALLINT, etc.
    Originally, Oracle database only had three data-types:
    CHAR
    DATE
    NUMBER
    If you're going to be working with Oracle database, then you need to adapt yourself to its limitations.
    So you'll probably need to define NUMBER data-types using scale and precision.
    (As Kuassi mentioned.)
    Good Luck,
    Avi.

  • Does oracle 8.1.6.0 jdbc thin driver support jdk1.3 and oracle 8.0.5 database ?

    I have downloaded oracle 8.1.6.0 jdbc thin driver(named classes12.zip) to run with jdk1.3 to access oracle 8.0.5, but when I compile and run the jdbccheckup.java downloaded from oracle website like this:
    javac -classpath d:\jdbc\classes12.zip jdbccheckup.java
    (compile succeed)
    java -classpath d:\jdbc\classes12.zip jdbccheckup
    an error occured:
    Exception in thread "main" java.lang.NoClassDefFoundError:jdbccheckup
    Why??????

    Try this isntead.
    java -classpath d:\jdbc\classes12.zip;. jdbccheckup
    an error occured:
    Exception in thread "main" java.lang.NoClassDefFoundError:jdbccheckup
    Why??????

  • Bug in Oracle JDBC thin driver (parameter order)

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

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

  • Bug in Oracle JDBC thin driver 8.1.6 ?

    Is there a known bug in Oracle JDBC thin driver version 8.1.6 that would
    prevent it from closing the open cursors ?
    Thank you,
    Horea

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

  • Error Code Definition for JDBC Thin driver

    Would like to know where I can find the definition of error codes
    for JDBC thin driver to Oracle 7 database. Right now, when I have
    database errors, I get SQL execption with CODE=XXXXXX. Need to
    know the definition of the error codes in order to decide whether
    the application shall retry or quit or do something else. Thank
    you in advance.
    null

    Hi,
    thin client session Language is controlled by java Locale.
    Based on testing code, ORA- messages are localized after the connection is successfully established. ORA- messages returned in the middle of connecting are in instance language.
    So, as far as I can say, you need to catch exceptions from DriverManager.getConnection(url, info); and translate them on your own.
    Once the connection is successfully returned, ORA- message language is defined by java Locale.
    Tests were performed on Oracle 10gR2 (both thin driver and DB).

  • Jdbc oracle jdbc-thin driver subname

    I am working on Windows 2000 environment, using oracle8i 8.1.7 JDBC-Thin driver for use with JDK 1.2.x. The oralce8i 8.1.7 database is on another linux box. I can access the linux box through its ip address, but not by its hostname since it's not accessiable by the dns server. In my code, in the JDBCUrl, I used ip address instead of the hostname, e.g. "jdbc:oracle:thin:@10.0.113.108:1521:ora1". But I got the error like: "java.sql.SQLException: Io exception: The Network Adapter could not establish the connection". If I add a entry in my working machine's hosts file to map the hostname, I can fix the problem. But I don't know if this is the solution, or there is other better solutions.
    Thanks
    null

    Using a hosts file entry is a common solution for problem where the dns lookup does not contain an entry for a RDBMS server platform.
    The real solution is to resolve this issue :
    "where the dns lookup does not contain an entry for a RDBMS server platform."

  • Oracle JDBC thin driver on NT vs IBM mainframe Linux

    We are develping an Java 3-tier web application on NT platform. The database is Oracle 9i. The JDBC Driver is Oracle thin driver (oracle.jdbc.driver in classes12.jar). Java is JDK1.3. We are told recently that we may need to deploy this application on IBM mainframe Linux systems when we go production. pplication server will be running on IBM mainframe Linux, and assume Oracle will be the same.)
    My question is if you know that we will be able to use the same Oracle thin driver that we use on NT platform when we deploy our application to IBM mainframe Linux system. Is there a specific JDBC driver that we must use when running application server and Oracle on IBM mainframe Linux
    Thanks for your help in advance.

    Hello,
    No, thin driver is same for all platforms (binary) - You must set SQL*Net on Linux only
    regards

  • Oracle JDBC thin driver question

    Does anyone know if there is a JDBC thin driver available for Oracle that supports "HTTP tunneling" of the SQLNET wire protocol?
    Such a driver would package the SQL*NET data stream into HTTP or HTTPS packets and connects to a Servlet proxy on the Web host that unpacks the data and forwards the SQL*NET stream to the Oracle RDBMS and returns the response the same way.
    This would help me overcome some firewall issues I'm seeing since HTTP/HTTPS ports are usually opened through a firewall. I know Sybase has a JDBC dirver that does this for their TNS protocol and was hoping some company has developed this for Oracle.
    Thanks in advance...

    The easiest thing to do is download it as an archive with your applet.
    Otherwise, you have to have the files on every client machine.
    For netscape, put the classes111.jar in the java classes folder typically:
    c:\ProgramFiles\Netscape\Communicator\Program\java\classes.
    I'd expect that IE would be setup in a similar way.

  • Oracle JDBC Thin Driver for oracle 9.2.0.4

    Hi,
    It would be nice if someone please guide me to the download of Oracle JDBC Thin Driver for oracle 9.2.0.4.
    Thanks in anticipation

    user566773,
    As far as I know, all Oracle JDBC drivers are meant to be backward compatible.
    According to the table on the following Web page, the latest Oracle JDBC driver can be used with Oracle 9.2.0.x DBMS.
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
    Good Luck,
    Avi.

  • JDBC Thin Driver 8.17 Release 2

    Is the Oracle Direct Driver (JDBC Thin Driver 8.17 Release 2) compatible with other oracle versions like 8.15 and 8.16? Is it backward compatible to older releases. I have tried it and it does work, but I want to make sure there are no known problems going backwards because we have several versions in our shop.
    Thanks
    Brian

    Rong Lu (guest) wrote:
    : I am using Oracle JDBC thin driver 8.0.5.0.0 to query Oracle
    : 8.0.5 via SQL net. The problem I met is every time I try to
    : retrieve data for varchar2 (over 2k), it get truncated and
    only
    : return the first 2k without throwing any warning or exception.
    : I tried getString(), getAsciiStream() and getBinaryStream(),
    and
    : the results are still the same. The SQL Net works fine, since
    it
    : successfully returns over 2k varchar2 type data when programing
    : with PERL.
    check the following oracle jdbc faq link :
    http://technet.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm
    #_36_
    null

  • Oracle JDBC Thin Driver and Firewall Problem

    Hi!
    We have Oracle 8.1.5 and Websphere App Server. There is a
    firewall between the two. A servlet creates a connection pool
    (not that of Wesphere's). The frontend is JSP/HTML (no applets).
    The servlet uses the Oracle JDBC Thin Driver for DB Connections.
    The problem is - Once the connection is freed, the connection
    pool is not being able to retrieve it and hence it created
    another one, thus reaching the max. # of connections and the
    system hangs. Restarting the DB service flushes the connection
    and the application starts running again...
    There was a similar problem discussed in this forums long ago. I
    have not yet tried mentioning the firwall port and IP in the
    connection string. But apart from that, is there any other
    setting I need to do (on firewall or for the connectionstring)
    to deal with this problem?
    Someone had suggested to punch a hole in the firewall for the DB
    port - but we can not really do that in the current scenario...
    I would appreciate if anyone could share their experience
    regarding how they resolved this issue.
    Thanks in advance,
    Vijaya.

    One more question -
    Can we use Oracle JDBC OCI driver? We do not have any appletes...
    Does it have firewall issues too? Is there any other driver that
    we can use?
    Thanks,
    Vijaya.

  • JDBC thin Driver 8.0.X Limit 2k for varchar2?

    I am using Oracle JDBC thin driver 8.0.5.0.0 to query Oracle
    8.0.5 via SQL net. The problem I met is every time I try to
    retrieve data for varchar2 (over 2k), it get truncated and only
    return the first 2k without throwing any warning or exception.
    I tried getString(), getAsciiStream() and getBinaryStream(), and
    the results are still the same. The SQL Net works fine, since it
    successfully returns over 2k varchar2 type data when programing
    with PERL.
    null

    Rong Lu (guest) wrote:
    : I am using Oracle JDBC thin driver 8.0.5.0.0 to query Oracle
    : 8.0.5 via SQL net. The problem I met is every time I try to
    : retrieve data for varchar2 (over 2k), it get truncated and
    only
    : return the first 2k without throwing any warning or exception.
    : I tried getString(), getAsciiStream() and getBinaryStream(),
    and
    : the results are still the same. The SQL Net works fine, since
    it
    : successfully returns over 2k varchar2 type data when programing
    : with PERL.
    check the following oracle jdbc faq link :
    http://technet.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm
    #_36_
    null

  • Jdbc thin driver to connect oracle as internal

    I need to connect to Oracle as Internal using jdbc driver, is there a way we can do this using jdbc thin driver. Actually I don't want to pass username and password as it will be harcoded in a properties file.
    Please let me know.

    Hi Minol,
    Have a look at this code example that shows how to Connect to Database as internal ( as sysdba ). In this code sample the properties are hard-coded, you can supply these Properties by loading them from a properties file.
    Connecting to Oracle Database with DBA privileges
    http://myjdbc.tripod.com/basic/codeindex.html
    The code snippet to load properties from a properties file
    //Import IO related classes
    import java.io.IOException;
    // Necessary support classes
    import java.util.Properties;
    import java.util.Enumeration;
    import java.util.ResourceBundle;
       * This method reads a properties file which is passed as
       * the parameter to it and load it into a java Properties
       * object and returns it.
       * @param file File path
       * @return Properties The properties object
       * @exception IOException if loading properties file fails
       * @since 1.0
      public static Properties loadParams(String file)
          throws IOException {
        // Loads a ResourceBundle and creates Properties from it
        Properties     prop   = new Properties();
        ResourceBundle bundle = ResourceBundle.getBundle(file);
        // Retrieve the keys and populate the properties object
        Enumeration enum = bundle.getKeys();
        String      key  = null;
        while (enum.hasMoreElements()) {
          key = (String) enum.nextElement();
          prop.put(key, bundle.getObject(key));
        return prop;
      }Regards
    Elango.

  • Jdbc thin driver connect oracle as internal

    I need to connect to Oracle as Internal using jdbc driver, is there a way we can do this using jdbc thin driver. Actually I don't want to pass username and password as it will be harcoded in a properties file.
    Please let me know.

    Hi Minol,
    Have a look at this code example that shows how to Connect to Database as internal ( as sysdba ). In this code sample the properties are hard-coded, you can supply these Properties by loading them from a properties file.
    Connecting to Oracle Database with DBA privileges
    http://myjdbc.tripod.com/basic/codeindex.html
    The code snippet to load properties from a properties file
    //Import IO related classes
    import java.io.IOException;
    // Necessary support classes
    import java.util.Properties;
    import java.util.Enumeration;
    import java.util.ResourceBundle;
       * This method reads a properties file which is passed as
       * the parameter to it and load it into a java Properties
       * object and returns it.
       * @param file File path
       * @return Properties The properties object
       * @exception IOException if loading properties file fails
       * @since 1.0
      public static Properties loadParams(String file)
          throws IOException {
        // Loads a ResourceBundle and creates Properties from it
        Properties     prop   = new Properties();
        ResourceBundle bundle = ResourceBundle.getBundle(file);
        // Retrieve the keys and populate the properties object
        Enumeration enum = bundle.getKeys();
        String      key  = null;
        while (enum.hasMoreElements()) {
          key = (String) enum.nextElement();
          prop.put(key, bundle.getObject(key));
        return prop;
      }Regards
    Elango.

Maybe you are looking for

  • Installing Windows 7 OEM on Maverick

    Apple Store advised me to get a Windows 7 OEM 64 bit disc for my 2013 macbook pro: http://www.amazon.com/Windows-Premium-System-Builder-Packaging/dp/B00H09BB16/ref =sr_1_1?s=software&ie=UTF8&qid=1393131478&sr=1-1&keywords=windows+7 .  This is a gener

  • 52"Samsung now flickering

    In January I hooked up my 52" Samsung LCD to the MacMini using a Belkin DVI to HDMI Cable. All worked fine until 20 minutes ago. Now every 5-10 minutes the screen flickers with several bands of green horizontal linse going through the picture. I have

  • ISE BYOD Error: "We are unable to determine access privileges" on redirect

         I am running ISE 1.1.1 and have gone through the design guide and setup the certificate based wireless authentication and device registration process using the ISE as a SCEP proxy for handing out certificates.  On the device registration portal

  • Export workflow with Compressor or QT?

    I finally make the move to Studio Pro5 and FCP5, love the FCP and now have a confusing problem with a movie that I want to export with Chapters to DVDSP5. Choices: 1. Export to QT, save as (not conversion), self contained from FCP with chapters, only

  • Restore the dropped tablespace using RMAN?

    Hello, I have done a oracle tablespace re-org for PSAPPOOLD,PSAPPOOLI. Now I want to restore only the OLD PSAPPOOLD,PSAPPOOLI tablespace using TAPE backup via RMAN.  The probelm is I have dropped the old tablespace during re-org which is a part of th