<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Using the JDBC 8i, 9iR1, Oracle's DATE datatype is mapped to the "java.sql.Timestamp" class. However, the new "ojdbc14.jar" driver maps DATE to "java.sql.Date", and "java.sql.Date" only holds a date (without a time), whereas "java.sql.Timestamp" holds both a date and a time.




    Subject: JDBC 920x Date/TimeStamp mapping
    Type: BULLETIN
    Status: UNDER_EDIT
    Content Type: TEXT/PLAIN
    Creation Date: 29-JUL-2003
    Last Revision Date: 04-OCT-2004


    PURPOSE
    -------
       Clarify the use of oracle.jdbc.V8Compatible property flag
     
    SCOPE & APPLICATION
    -------------------
    JDBC 920x Date/TimeStamp mapping is different from JDBC 8i, 9iR1.
    <TITLE FOR MAIN ARTICLE TEXT>
    -----------------------------
    Summary of  features afftected by oracle.jdbc.V8Compatible.
     
    As of 9.2.0.1.0 Oracle realigned its DATE type with the java.sql.Types.DATE type.
    Prior to this
    java.sql.DATE and  java.sql.TIMESTAMP were mapped to java.sql.Types.TIMESTAMP.
     
    This mapping change applies to JDBC default mapping (i.e when getObject() is
    used for Date column.
     
    example:
    select sysdate from dual;
    ...
    while (rset.next ())  {
    System.out.println("getObject for sysdate  : " +
    rset.getObject(1).getClass().getName());
    System.out.println("getDate for sysdate :" +
    rset.getDate(1).getClass().getName());
    System.out.println("getTimetamp for sysdate :" +
    rset.getTimestamp(1).getClass().getName());
    }
     
    Prior to 9201, this will return
    getObject for sysdate  : java.sql.Timestamp      <<<<
    getDate for sysdate :java.sql.Date
    getTimetamp for sysdate :java.sql.Timestamp
     
    As of 9201 onward the following will be returned
     
    getObject for sysdate  : java.sql.Date        <<<<<
    getDate for sysdate :java.sql.Date            >> no change
    getTimetamp for sysdate :java.sql.Timestamp   >> no change
     
     
     
    Note: java.sql.Date has no time portion whereas java.sql.Timestamp does.
     
     
    With this change in Datatype mapping, some application will fail and/or generate
    incorrect results when JDBC driver is upgraded from 8i/ 9iR1 to 920x JBDC driver.
    To maintain compatibility and keep applications working after upgrade, a compatibility flag was
    Provided.  Developers now have some options:
     
    1>
    Use oracle.jdbc.V8Compatible flag.
     
    JDBC Driver does not detect database version by default.
    To change the compatibility flag for handling TIMESTAMP datatypes,
    connection property 'oracle.jdbc.V8Compatible' can be set to
    'true' and the driver behaves as it behaved in 8i, 901x, 9200
    (with respect to TIMESTAMPs).
    By default the flag is set to 'false'. In OracleConnection constructor
    the driver obtains the server version and set the compatibility flag
    Appropriately.
     
    java.util.Properties prop = new java.util.Properties ();
    prop.put ("oracle.jdbc.V8Compatible", "true");
    prop.put ("user", "scott");
    prop.put ("password", "tiger");
    String url ="jdbc:oracle:thin:@host:port:sid";
    Connection conn = DriverManager.getConnection (url,prop);
     
     
     
    With JDBC 10.1.0.x, in instead of the connection property, the following system
    property can be useed
    java -Doracle.jdbc.V8Compatible=true .....
     
     
     
    Note: This flag is a client only flag that governs the Timestamp and Date mapping.
    It does not affect any Database feature.
     
     
     
    2> use set/getDate and set/getTimestamp   when dealing with Date and TimeStamp column datatype accordingly.
    9i server  supports both Date and Timestamp column types
     
    DATE is mapped to  java.sql.Date and TIMESTAMP is mapped to java.sql.Timestamp
     
    I> using setTimestamp
     
    PreparedStatement pstmt = conn.prepareStatement(
    "SELECT count(*) from  tstable where tscol between ? and ?");
    // tscol of type Timetamp (or it can be Date)
     
    String s = new String("2003-01-14 10:00:00.000000000");
    Timestamp ts1 = Timestamp.valueOf(s);
    pstmt.setTimestamp(1, ts1); // Timestamp
     
    String s2 = new String("2003-01-16 10:00:00.000000000");
    Timestamp ts2 = Timestamp.valueOf(s2);
    pstmt.setTimestamp(2, ts2); // Timestamp
    ...
     
     
    II>using setDate
     
    PreparedStatement pstmt = conn.prepareStatement(
    "SELECT count(*) from  tstable where datecol between ? and ?");
    // datecole of type Date
     
    /*
    pstmt.setDate(1,new java.sql.Date(System.currentTimeMillis()));
    pstmt.setDate(2,new java.sql.Date(System.currentTimeMillis()));
    */
     
    SimpleDateFormat start_dt_in1 = new SimpleDateFormat("2002-09-18 00:00:00");
    SimpleDateFormat start_dt_in2 = new SimpleDateFormat("2003-09-18 00:00:00");
    pstmt.setDate(1,start_dt_in1);
    pstmt.setDate(2,start_dt_in2);
     
     
     
    Summary of  features afftected by oracle.jdbc.V8Compatible.
     
    Is backward compatible (with oracle.jdbc.V8Compatible)?
    
     
     
    * Examples:
    ..
    The following will fail   when using JDBC 9iR1, 9iR2 connecting 817 server since the
    817 did not support Timestamp
     
     
    Connection conn = DriverManager.getConnection(url, "scott",  "tiger");
    // Prepare a statement to cleanup the emp table
    Statement  stmt = conn.createStatement();
    try {
    stmt.execute("delete from EMP where EMPNO = 1");
    } catch (SQLException e) {
    }
    try {
    stmt.execute("INSERT INTO EMP (EMPNO, ENAME, HIREDATE) VALUES (1, 
    'ALI', {ts '2003-04-14 14:19:24.94'})");
    } catch (SQLException e) {
    e.printStackTrace();
    }
     
    Error : Exception in thread "main" java.sql.SQLException: ORA-00904: invalid column name
     
    Solution you need
    1> fix for Bug 2640192 (included in 9204)
    2> oracle.jdbc.V8Compatible", "true"
     
     
     
    In earlier versions of JDBC drivers  SQL FUNCTION "TS" was mapped to "to_date" .   So, the query
     
    select {ts '2002-10-18 18:02:00'} from dual;
    was translated by JDBC to,
    select TO_DATE ('2002-10-18 18:02:00',  'YYYY-MM-DD HH24:MI:SS') from dual;
     
     
    With 9i Timestamp is supported in the database and also by 9203 JDBC Drivers.
    So the query
     
    select {ts '2002-10-18 18:02:00'} from dual;
     
    is now translated  by JDBC to
     
    select TO_TIMESTAMP('2002-10-18 18:02:00', 'YYYY-MM-DD HH24:MI:.SS.FF') from dual;
     
     
    Known issues:  There is some performances issue when set/getTimestamp
    Bug 3037615
    Bug 2770935
    These bugs are very likely duplicate.
     
     
    The following code will no longer work with 9203+ unless V8 flag is set to true
     
    Timestamp start_dt_in = Timestamp.valueOf("2002-09-18 00:00:00");
    Timestamp now_period_start_dt ;
    PreparedStatement stmt = null;
    ResultSet rs = null;
     
    System.out.println("start_dt_in="+  start_dt_in );
     
    try {
    stmt = conn.prepareStatement( "SELECT TRUNC(?) FROM DUAL" );
    stmt.setTimestamp( 1, start_dt_in );
    rs = (OracleResultSet) stmt.executeQuery();
    if ( rs.next() ) {
    now_period_start_dt = rs.getTimestamp( 1 );
    System.out.println("Curr Period Start="+  now_period_start_dt );
    }
     
     
    will generate
    Exception in thread "main" java.sql.SQLException:
    ORA-932: inconsistent datatypes
     
     
    Reason : trunc ( )  supports Date columns and does not support  Timestamp  (this is an RDBMS issue).
    So, you need to set the V8 flag to true
     
    Another bug that changed the Date/Timetamp mapping is  2428427 to comly with
    J2EE 1.3 CTS.  This was fixed in 9014 and it specific to classesdmx*.zip/jar
    (the *dms* jar filed mainly used by iAS/OC4J).  These *dms* jar files, by the
    default value for oracle.jdbc.J2EE13Compliant  is true.  in classes111.zip
    classes12.jar and ojdbc14.jar/zip the default is false.
     
    One can toggel this flag  true/false by
     
    java -Doracle.jdbc.J2EE13Compliant=true|false
     
     
    example of of sample runs:
     
    query used :"select sysdate from dual"
    classes12dms.jar used.
     
     
    Driver Version      Object Type
    ==============      ===========
    9.0.1.3.0         java.sql.Timestamp >> fix for 2428427 NOT included
    9.0.1.4.0         java.sql.Date   >> fix for 2428427 INCLUDED
    9.0.1.5.0         java.sql.Date   >> fix for 2428427 INCLUDE
     
    In JDBC 9014+ ,to keep older (9013) behavior  simply run the application with
     
     
    $java -Doracle.jdbc.J2EE13Compliant=false .....
     
     
    However please note that J2EE 1.3 CTS require that Date to mapped to
    java.sql.Date.
    

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲视频网站在线观看| 亚洲欧洲精品在线| 国产一级片免费看| 亚洲网站在线免费观看| 国产18禁黄网站免费观看| 两个人的视频www免费| 亚洲一级毛片在线播放| 亚洲一区二区三区无码影院| 久9这里精品免费视频| 亚洲AV成人一区二区三区在线看| 国产在线观看www鲁啊鲁免费| 国产免费久久精品丫丫| 久久精品国产亚洲AV大全| 国产大片51精品免费观看| 免费毛片在线看不用播放器| 亚洲欧洲免费无码| 亚洲网站在线观看| 日韩亚洲国产综合久久久| 91成年人免费视频| a毛片免费全部在线播放**| 亚洲精品天堂成人片AV在线播放 | 57pao国产成视频免费播放| 亚洲午夜理论片在线观看| 亚洲va中文字幕无码久久 | 亚洲噜噜噜噜噜影院在线播放| 亚洲成A人片在线观看无码3D| 120秒男女动态视频免费| 久久国产精品免费一区| 亚洲精品无码久久久久久| 亚洲综合小说久久另类区| 国产午夜亚洲精品午夜鲁丝片| 天天天欲色欲色WWW免费| 亚洲免费闲人蜜桃| 老司机69精品成免费视频| 成人a毛片免费视频观看| 亚洲美国产亚洲AV| 激情亚洲一区国产精品| 91亚洲国产在人线播放午夜 | 日韩一区二区三区免费播放| 亚洲熟妇av午夜无码不卡| 亚洲国产精品网站久久|