[英]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.