2012-05-14 111 views
1

我從數據庫中選擇ts:ts = Select ts from ...所以現在我在我的變量中有oracle.sql.TIMESTAMP。現在我需要選擇此時間戳記中的所有記錄:選擇帶時間戳的記錄

select * from ... where time = ts 

我該如何做到這一點?

+0

爲什麼不能在這個單獨的SQL語句來完成? – Chandra

回答

4

嘗試PreparedStatementJavadoc):

PreparedStatement pstmt = connection.prepareStatement("select * from ... where time = ?"); 
pstmt.setTimestamp(1, timestamp); 
ResultSet rs = pstmt.executeQuery; 
+0

sory但這個int工作:我得到這個異常:警告:無法執行:選擇*從表where where ts ='[email protected]'因爲:ORA-01858:找到一個非數字字符的數字預計 – hudi

+0

這是因爲你需要'java.sql.Timestamp',而不是'oracle.sql.Timestamp' –