首先創建CallableStatement
,然後綁定該值。這就是像換
// clstmt.setDate("date", new java.sql.Date(currentDate.getTime()));
clstmt = con.prepareCall("exec vcs_gauge 'vs1_bag', 'd', 'date'");
clstmt.setDate("date", new java.sql.Date(currentDate.getTime()));
您的語句的順序你得到了NullPointerException
因爲clstmt
是null
直到你prepareCall()
。
編輯
我覺得你的語法應該是這樣
clstmt = con.prepareCall("{call vcs_gauge('vs1_bag', 'd', ?) }");
clstmt.setDate(1, new java.sql.Date(currentDate.getTime()));
編輯2
根據您的更多詳細信息,
String sql = "exec vcs_gauge @gauge_name=?,@first_rec_time=?,@last_rec_time=?";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
clstmt = con.prepareCall(sql);
clstmt.setString(1, "vs1_bag");
clstmt.setString(2, df.format(d));
clstmt.setString(3, df.format(currentDate));
顯示整個代碼。 – 2014-11-03 05:26:48
日期d =新日期(); date currentDate = new Date(System.currentTimeMillis() - 3600 * 1000); public String [] [] getDbTable() {int i = 0; \t String [] [] a = new String [3600] [16]; clstmt = con.prepareCall(「exec vcs_gauge'vs1_bag','d','date'」); clstmt.setDate(「date」,new java.sql.Date(currentDate.getTime())); clstmt.execute(); rs = clstmt.getResultSet(); while(rs.next()) {for(int j = 0; j <16; j ++) { a [i] [j] \t = rs.getString(j + 1); } i ++; } finally {closeConnection(); } return a; } 這是我的JAVA CODE.SP有3個參數和最後兩個是日期類型。 – MES 2014-11-03 06:47:27
@ Fumu7上面提到的是我的代碼。我知道它是以糟糕的方式呈現的,因爲我是新的堆棧流。 – MES 2014-11-03 06:49:08