![](/img/trans.png)
[英]How to fix BootReciever java.lang.NullPointerException?
[英]How to fix java.lang.NullPointerException
我的Java代碼在存儲過程調用中將參數作為系統當前日期時間和時間之前一小時傳遞。
Date d = new Date();
Date currentDate = new Date(System.currentTimeMillis() - 3600 * 1000);
clstmt.setDate("date", new java.sql.Date(currentDate.getTime()));
clstmt = con.prepareCall("exec vcs_gauge 'vs1_bag', 'd', 'date'");
當我運行相應的JSP頁面時,將引發java.lang.NullPointerException
。
首先創建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));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.