Oracle JDBC thin driver(10g) returns "int/smallint" as JDBC Decimal type

Hi,
I am using Oracle type 4 thin JDBC driver for 10g. In our code we decide
column type by querying the database using database metadata (as code snippet below)
DatabaseMetaData dbmd = Connection.getMetaData() ;
ResultSet rs = dbmd. getColumns() ;
String fieldName = rs.getString("COLUMN_NAME");
short dataType = rs.getShort("DATA_TYPE");
String typeName = rs.getString("TYPE_NAME");
Now, if I have a table with datatype "integer", "smallint" etc,
DATA_TYPE returned from above is "3" , which is in JDBC is defined constant
for "java.sql.Types.Deciaml"
Question is , How do i exactly get DATA_TYPE code for
"integer" or "smallint" and not "Decimal" ?
I have tested with few other databases with above snippet code and they do return actual DATA_TYPE as "integer" or "smallint"
This is with Oracle 10g database and Oracle 10g thin (type4) jdbc driver.
Thanks,
Chirag

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.

Similar Messages

  • Oracle JDBC thin driver 10g exceptions

    Can anyone tell me where I can find more resources about exceptions what I should expect if one node in cluster fails.
    Let assume that I am using WebLogic server.
    Thanks,

    We had a major problem in which we tried to roll the
    web app over to running against an Oracle database,
    and the number of open connections in our pooling
    code (that worked fine with the old database) blew up
    when lots of users started getting onto the site.
    The connections just were not being released, That statement is non-sensical.
    By definition the only point of a connection pool is to NOT release connections.
    and any JDBC calls starting spitting out exceptions,
    and the Oracle 10g thin client driver was saying that
    the maximum number of sessions were open (we were in
    the hundreds--we have a per-CPU license, so that
    shouldn't be an issue).
    We're not sure what to test right now. Whether we
    use Statements or PreparedStatements, we try to
    always close the Statement (which should close the
    ResultSet, if there is one) and then in the finally
    part of our try-catch-finally, we try to close the
    connection. Is that all we need to do? You must always close the result set first.
    Then you must always close the statement.
    Then you need to return the connection to the pool - explicitly. Usually, these days, that is done by calling the close method. It is certainly possible that your pool uses another method though.
    Can you
    think of anything we should be looking for?It is possible you have connection pool mis-configured as well.

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

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

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

  • JDBC Thin-Driver and Oracle Stored Procedure

    I've got a Oracle stored procedure which returns a Oracle record.
    How can I retrieve the record in java using the JDBC Thin-Driver ?
    Record:
    TYPE messagerec IS RECORD
    (log_level VARCHAR(2), timestamp VARCHAR2(19), text VARCHAR2(200));

    Using PL/SQL BOOLEAN, RECORD Types, and TABLE Types:
    Oracle SQLJ and JDBC do not support calling arguments or return values of the
    PL/SQL BOOLEAN type or RECORD types. Also, when using the Thin driver, they
    do not support calling arguments or return values of PL/SQL TABLE types (known
    as indexed-by tables). TABLE types are supported for the OCI driver.
    Check the following guide,
    http://otn.oracle.com/tech/java/sqlj_jdbc/pdf/a96655.pdf

  • Is JDBC  thin driver 10.1.0.3 compatible with ORACLE-10.2.0.2.0 ?

    Hi Everyone,
    Please let me know whether the JDBC thin driver 10.1.0.3 Driver compatible with the oracle server 10G version 10.2.0.2.0? We are facing some issues with the compatibility.
    The Errors we are getting is : StaleConnectionException while we are using the driver from the Websphere.
    Please let us know..Very Urgent.
    Thanks in Advance,
    Samuel.
    Message was edited by:
    user637857

    Hi Legatti,
    Thanks for taking time out and replying me.
    We dont know the reason why that error is being caused. Because the error is caused on the production we are not able to make any trail and errors. If we are sure that the driver compatibility is causing the error then we can go ahead and download the latest driver. If the latest driver will solve the problem we have to convince the client that the error is caused due to the incompatible driver. So if you have any documents/information supporting that please help.
    Thanks
    Samuel.

  • Oracle server side jdbc thin driver throws ORA-01017

    We upgraded our database to 11.2.0.1 from 9.2.0.6.
    When we try to connect to an external database from Oracle JVM using server side jdbc thin driver, it throws invalid user id/password error.
    The below test code simulates the issue and is not working on the upgraded instance. The same code is working in fine in other 11.2.0.1 instances. It worked fine before upgrade. In all cases, we are connecting to the same target database instance which is also in 11.2.0.1. It fails only on this database.
    SEC_CASE_SENSITIVE_LOGON is set to false.
    Any inputs will be highly appreciated.
    Code:_
    create or replace and compile java source named TestConn as
    import java.sql.SQLException;
    import oracle.jdbc.OracleDriver;
    import oracle.jdbc.OracleConnection;
    import java.sql.DriverManager;
    public class TestConn {
         public  static String runTest() {
          String msg = "Start";
          OracleConnection tempOC = null;
          try {
          String pUrl = "jdbc:oracle:thin:@dev:1521:dev";
          String pUser = "tst_user";
          String pPwd = "dummy";
          DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
          tempOC = (OracleConnection)DriverManager.getConnection(pUrl, pUser, pPwd);
    msg = "Success";
    } catch (SQLException sqle) {
          System.out.println(sqle.toString());
          sqle.printStackTrace();
          msg = "Failure";
            return msg;
    CREATE OR REPLACE FUNCTION test_conn RETURN VARCHAR2
    AS LANGUAGE JAVA
    NAME 'TestConn.runTest() return java.lang.String';
    set serverout on
    declare
    c varchar2(4000);
    begin
    dbms_java.set_output(5000);
    c:=test_conn();
    dbms_output.put_line(c);
    end;
    / Error Message_
    java.sql.SQLException: ORA-01017: invalid username/password; logon denied
    java.sql.SQLException: ORA-01017: invalid username/password; logon denied
           at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
           at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:388)
           at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:381)
           at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:564)
           at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:431)
           at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
           at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
           at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:366)
           at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java)
           at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:359)
           at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java)
           at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
           at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
           at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
           at java.sql.DriverManager.getConnection(DriverManager.java)
           at java.sql.DriverManager.getConnection(DriverManager.java)
           at TestConn.runTest(TESTCONN:22) Edited by: sskumar on Mar 6, 2011 1:12 PM

    At the time our issue was resolved, the bug was not published. And, I was told, there was no information in metalink about the isue. I am not sure whether they published some thing in the last few weeks.
    This is what resolved our issue.
    Step 1: alter system set java_jit_enabled=FALSE;
    Step 2: Try your test case. If it is the same issue as ours, your test case will be successful. If it succeeds, Go to step 3. If it does not succeed, it is a different issue.
    Step 3: alter system set java_jit_enabled=TRUE;
    Step 4: Run your test case. If it is the same issue, it is expected to fail. Go to Step 5 in case of failure.
    Step 5: Delete all rows from table java$mc$
    Step 6: Restart the database
    Step 7: Run your test case. It is expected to be successful.

  • Oracle JDBC Thin-Driver: Connection still valid (db still open)?

    Hi,
    I've got a problem with my program. The app opens a connection to an Oracle Database usingt the Oracle JDBC Thin.Driver. Everything works just fine but I can't figure out a way how to find out wheter the connection is still valid, e.g. if the database is still open?
    connection.isClosed() return always false :(
    Any help is appreciated.
    Thanks,
    Spaulding

    Hi oracle_guru,
    unfortunately it's not that easy. :(
    You can't just check for
    if(conn == null)since the connection won't realize when the db shuts down.
    Therefore I created a connection-watcher-thread which uses a prepared statement to check every once in while if the connection is still valid.
    Nevertheless, thanks for you reply,
    Spaulding

  • 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

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

Maybe you are looking for

  • New iPad 2 does not look as good as old ipad?

    Just got my iPad 2 and first thing I notice is the screen does not look as good as my old iPad.  There's a difference in brightness (dimmer) but that's fine, I just increase the brightness.  However, even after adjusting to approx same level of brigh

  • There is no iView available for system "SAP_ERP_Manufacturing"...

    Hi out there, I have imported the business packages Common Parts 1.2 and Maintenance Technician 1.2 in our portal testsystem (nw7, sps18). after setting up a system with alias SAP_ECC_MANUFACTURING and asigning the role com.sap.pct.erp.maintech.maint

  • Help needed in creating an autorun CDR

    I want to create a CD that will play in both a PC and a MAC, that is basically an offline copy of a website I have built and will automatically open the index.html page of this website when loaded into either a PC or a MAC. I have created an autorun

  • How to use a parameter passed to stored procedure in cursor?

    I am rather new to Oracle stored procedures and I'm sure that this is rather simple. Could someone tell me how to do the following: I would like to pass the variable status into my stored procedure and then use it in the where clause when defining my

  • Many original dates of photos are missing or wrong

    I have had a lot of issues with my iPhoto program. After many trips to the Genius Bar and numerous hours with phone techs, I am now rebuilding my library, starting with a backup of it from before the corruption. When I "get info" of a picture, I noti