Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle Dates and Java Dates and selecting the former into the later

Re: Oracle Dates and Java Dates and selecting the former into the later

From: Chet Justice <chet.justice_at_pfsf.org>
Date: 1 Jun 2005 06:18:49 -0700
Message-ID: <1117631928.890313.246020@g47g2000cwa.googlegroups.com>

mike.jones_at_xenicom.com wrote:
> I've been requested to move all of our DATE columns over to timestamps
> as the Java date object does not have a time element, when a query is
> thrown to the DB and this selects a date column, the time section is
> automaticallly lost via
> JDBC.
>
> This sounds like a bag of crock to me, I'm surprised that the easiest
> option is to needlessly convert an awful lot of columns to timestamps,
> just so that JDBC can get at the time portion. I'm also concerned that
> the implication of this is more than it just allowing us to get date /
> times into Java. What are the storage implications? or are Dates /
> Timestamps synonymous at an internal level like INTEGERS, FLOATS etc?
>
> Thanks,
>
> Mike,

I didn't lose the time element:

import java.sql.*;
import oracle.jdbc.driver.*;

public class OracleDate
{
  private static String SQL = "SELECT sysdate FROM dual";   private static Statement stmt = null;

  private static Connection conn = null;
  private static String username = "cdjustice";
  private static String password = "testing";
  private static String url =
"jdbc:oracle:thin:@myserver:1521:testing";   private static ResultSet rs = null;

  public static void main(String[] args) throws SQLException   {
    try
    {

      DriverManager.registerDriver(new OracleDriver());
      conn = DriverManager.getConnection(url, username, password);
      stmt = conn.prepareStatement(SQL);
      rs = stmt.executeQuery(SQL);

      while (rs.next())
      {
        System.out.println("Result:  " + rs.getString("SYSDATE"));
      }

    }
    catch (SQLException ex)
    {
      System.out.println(ex);
    }
    finally
    {
      if (conn != null) { conn.close(); conn = null; }
      if (stmt != null) { stmt.close(); stmt = null; }
      if (rs != null) { rs.close(); rs = null; }
    }
  }
}

Result: 2005-06-01 09:19:27.0 Received on Wed Jun 01 2005 - 08:18:49 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US