FileDocCategorySizeDatePackage
TestDateTypes.javaAPI DocExample1785Thu Nov 30 14:20:34 GMT 2000None

TestDateTypes

public class TestDateTypes extends Object

Fields Summary
Connection
conn
Constructors Summary
public TestDateTypes()

  try {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");
  }
  catch (SQLException e) {
   System.err.println(e.getMessage());
   e.printStackTrace();
  }
 
Methods Summary
protected voidfinalize()

  if (conn != null) { try { conn.close(); } catch (SQLException ignore) { } }
  super.finalize();
 
public static voidmain(java.lang.String[] args)

  new TestDateTypes().process();
 
public voidprocess()

  SimpleDateFormat  sdf  = new SimpleDateFormat("yyyyMMddhhmmss");
  Date              date = new Date(System.currentTimeMillis());
  Time              time = new Time(System.currentTimeMillis());
  Timestamp         stmp = new Timestamp(System.currentTimeMillis());
  Statement         stmt = null;
  int               rslt = 0;
  try {
   stmt = conn.createStatement();
   rslt = stmt.executeUpdate(
    "insert into test_data_types ( a_date ) values ( to_date( '" + 
    sdf.format(date) + "', 'YYYYMMDDHH24MISS' ) )");
   rslt = stmt.executeUpdate(
    "insert into test_data_types ( a_date ) values ( to_date( '" + 
    sdf.format(time) + "', 'YYYYMMDDHH24MISS' ) )");
   rslt = stmt.executeUpdate(
    "insert into test_data_types ( a_date ) values ( to_date( '" + 
    sdf.format(stmp) + "', 'YYYYMMDDHH24MISS' ) )");
  }
  catch (SQLException e) {
   System.err.println(e.getMessage());
  }
  finally {
   if (stmt != null) try { stmt.close(); } catch (SQLException ignore) { }
  }