經與下面的代碼有很多問題:SQL準備語句無效列索引?
public static ArrayList getKundeNrToOrder (String s_date, String e_date) throwsSQLException
{
ResultSet rs = null;
Connection con = null;
int tal = 0 ;
try
{
Class.forName(DB.driver);
con = DriverManager.getConnection(DB.URL, DB.ID, DB.PW);
String query = "SELECT ORDRE_NR FROM ORDRE_INFO WHERE S_DATE BETWEEN TIMESTAMP '? 00:00:00 CET' AND TIMESTAMP '? 00:00:00 CET' or E_DATE BETWEEN TIMESTAMP '? 00:00:00 CET' AND TIMESTAMP '? 00:00:00 CET' OR S_DATE <= TIMESTAMP '? 00:00:00 CET' AND E_DATE >= TIMESTAMP '? 00:00:00 CET';";
PreparedStatement prest = con.prepareStatement(query);
String S_DATE = s_date;
String E_DATE = e_date;
System.out.println("jens");
prest.setString(1,S_DATE);
prest.setString(2,E_DATE);
prest.setString(3,S_DATE);
prest.setString(4,E_DATE);
prest.setString(5,S_DATE);
prest.setString(6,E_DATE);
rs = prest.executeQuery();
它崩潰,並給我一個錯誤「無效的列索引......」
任何人有一個想法,爲什麼失敗?我試圖給它這個查詢,而不是它的作品完美。
String query = "SELECT ORDRE_NR FROM ORDRE_INFO WHERE
S_DATE BETWEEN TIMESTAMP '2007-10-10 00:00:00 CET'
AND TIMESTAMP '2009-10-10 00:00:00 CET'
or E_DATE BETWEEN TIMESTAMP '2007-10-10 00:00:00 CET'
AND TIMESTAMP '2009-10-10 00:00:00 CET'OR S_DATE <= TIMESTAMP '2007-10-10 00:00:00 CET'
AND E_DATE >= TIMESTAMP '2009-10-10 00:00:00 CET'";
你確定你連接到正確的數據庫和架構? –
是的:)有連接 – HOervald