我必須使用JDBC寫入數據庫(hibernate/ibatis不是一個選項),我的數據庫是Oracle 11g。JDBC:抱怨無效標誌,但似乎很好
創建以下查詢:insert into user(user_id, username, age, creation_ts) values(seq_userid.NEXTVAL, 'Jack', 19,TO_TIMESTAMP('14/12/2010 15/09/46', 'DD/MM/RR HH24/MI/SS'));
但是我statetement.execeuteUpdate(above sql)
。生成無效的符號異常。 但是,當我在松鼠中執行查詢它得到承諾很好。 有誰知道爲什麼會發生這種情況?
Edit:
user table:
id: number : not null
username varchar2(30) not null
age number(10) not null
creation_ts timestamp not null
Error:
ORA-00911: invalid character
Java snippet:
try
{
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
String url = "privatized";
Connection conn = DriverManager.getConnection(url, "username", "password");
Statement st = conn.createStatement();
Format formatter = new SimpleDateFormat(dateTimeFormatString);
String formattedDate = formatter.format(Calendar.getInstance(TimeZone.getDefault()).getTime());
StringBuilder insertQuery = new StringBuilder("insert into user(user_id, username, age, creation_ts) values(seq_userid.NEXTVAL,");
insertQuery.append(username);
insertQuery.append(",");
insertQuery.append(age);
insertQuery.append(",TO_TIMESTAMP('");
insertQuery.append(formattedDate);
insertQuery.append("', 'DD/MM/RR HH24/MI/SS'));");
System.err.println(insertQuery.toString());
st.executeUpdate(insertQuery.toString());
conn.close();
} catch (SQLException ex){
System.err.println(ex.getMessage());
System.err.println(ex.getCause().toString());
ex.printStackTrace();
System.out.println("=========================================");
} catch(Exception ex) {
System.err.println(ex.getMessage());
}
這將有助於查看有關表格的規格。 Java代碼摘錄也可能有幫助。 – Jules 2010-12-14 14:15:41
它有一個oracle異常嗎? – HamoriZ 2010-12-14 14:16:20
什麼是無效符號異常?你可以粘貼錯誤/堆棧跟蹤? – 2010-12-14 14:19:00