2011-10-25 9 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); 

//私は、ID(我々はmytimestampには、このINSERTのように使用することができますINSERT文で、データベース内のタイムスタンプ値を追加するには、こののprepareStatementここでTIMESTAMPを使用することができますどのように、made_on)VALUES(1、TIMESTAMP '2005-05-13 07:15:31.123456789');だから私はこれをprepareStatementでどのように使うことができますか?はどのようにJDBC PreparedStatementを使用してOracleにTIMESTAMP列値に挿入する

  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')と書いてください。

関連する問題