String s1 = "create table testing " +
"(id number NOT NULL PRIMARY KEY, " +
"url varchar(1000) NOT NULL, " +
"urlHash varchar(1000) NOT NULL, " +
"contentHash varchar(1000), " +
"modDate date, " +
"contentLocation varchar(1000), " +
"status integer, " +
"lastCrawlDate date) ";
String s2 = "create sequence " +sequenceName+ " start with 1 increment by 1 nomaxvalue";
stmt=conn.createStatement();
stmt.executeUpdate(s1);
stmt.executeUpdate(s2);
以下合并声明有什么问题我总是得到错误
Missing IN or OUT parameter at index:: 8
我正在尝试将字符串日期时间转换为准备语句中的oracle sql中的Date dataType
ps = conn.prepareStatement(
"MERGE INTO testing " +
"USING ( SELECT ? AS url, " + // We will maybe add this record
" ? AS urlHash, " +
" ? AS contentHash, "+
" TO_DATE(?, 'YYYY-MM-DD'T'HH24:MI:SS'Z'') AS modDate, "+
" ? AS contentLocation, "+
" ? AS status, "+
" TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') AS lastCrawlDate "+
" FROM dual ) maybe "+
" ON (maybe.urlHash = testing.urlHash) "+
" WHEN MATCHED THEN "+
// We only need update the fields that might have changed
" UPDATE SET testing.contentHash = maybe.contentHash, "+
" testing.modDate = maybe.modDate, "+
" testing.contentLocation = maybe.contentLocation, "+
" testing.status = maybe.status, "+
" testing.lastCrawlDate = maybe.lastCrawlDate "+
// But only if the new record is more recent
" WHERE TO_CHAR(testing.modDate, 'YYYY-MM-DD'T'HH24:MI:SS'Z'') < TO_CHAR(maybe.modDate, ''YYYY-MM-DD'T'HH24:MI:SS'Z''') "+
" WHEN NOT MATCHED THEN "+
// Insert new URL record
" INSERT VALUES (test_seq.nextval, maybe.url, maybe.urlHash, maybe.contentHash, maybe.modDate, maybe.contentLocation, maybe.status, maybe.lastCrawlDate)");
ps.setString (1, "http://www.computergeeks.com");
ps.setString (2, "ahsasoiowiewie");
ps.setString (3, "sgasjwhwueybdbfndf");
ps.setString (4, "2011-07-28T23:54:14Z");
ps.setString (5, "c://");
ps.setLong (6, 0);
ps.setString (7, "2010-09-24 23:34:14");
ps.executeUpdate();
ps.close();
答案 0 :(得分:2)
第一次TO_DATE
调用中的日期格式不合适 - 您尝试在单引号字符串中使用单引号,因此最终未正确封闭。可能这会让解析器适合,导致一个不太明智的错误信息。
在Oracle日期格式中,文字位需要用双引号括起来,而不是单引号:
select TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') from dual;
您需要在SQL语句中嵌入格式'YYYY-MM-DD"T"HH24:MI:SS"Z"'
。确保正确地转义双引号,这样它们就不会终止Java字符串。
答案 1 :(得分:-1)
这可能与您的问题无关,但我遇到了同样的错误,我在SQL的开头碰巧有两条注释行。我将它们移到了底部,错误就消失了。