2011-10-25 99 views
0
String s1 = "create table crawler " + 
      "(id number NOT NULL PRIMARY KEY, " + 
      "url varchar(255) NOT NULL, " + 
      "urlHash varchar(255) NOT NULL, " + 
      "contentHash varchar(255), " + 
      "modDate TIMESTAMP(4), " + 
      "contentLocation varchar(100), " + 
      "status integer, " + 
      "lastCrawlDate TIMESTAMP(4)) "; 




      String s2 = "create sequence test_seq start with 1 increment by 1 nomaxvalue"; 
      //String s3 = "create or replace trigger inserttrigger before insert on test for each row begin select test_seq.nextval into :new.id from dual; end;"; 

      stmt=conn.createStatement(); 
      stmt.executeUpdate(s1); 
      stmt.executeUpdate(s2); 
      //stmt.executeUpdate(s3); 

//我如何在這裏使用TIMESTAMP在此prepareStatement添加數據庫時間戳值作爲Insert語句時,我們可以使用這樣INSERT INTO mytimestamp(ID ,made_on)VALUES(1,TIMESTAMP'2005-05-13 07:15:31.123456789');所以我如何在prepareStatement中使用它。如何使用JDBC的PreparedStatement插入timestamp列值在Oracle

  ps = conn.prepareStatement (
      "INSERT INTO crawler (id, url, urlHash, contentHash, modDate, contentLocation, status, lastCrawlDate) VALUES(test_seq.nextval,?,?,?,TIMESTAMP '?',?,?,TIMESTAMP '?')"); 

      ps.setString (1, "http://www.google.com"); 
      ps.setString (2, "swerrsdfsfdgfgrgthtyty"); 
      ps.setString (3, "1a10407d9a7997531aabe"); 
      ps.setString (4, "2005-05-13 07:15:31.123456789"); 
      ps.setString (5, "c://"); 
      ps.setLong (6, 302); 
      ps.setString (7, "2005-05-13 07:15:31.123456789"); 

      int count = ps.executeUpdate(); 

這樣我得到錯誤。此代碼有任何問題..

回答

1

而不是TIMESTAMP '?',請寫TO_TIMESTAMP(?, 'YYYY-MM-DD HH24:MI:SS.FF')

相關問題