2014-11-03 3 views
0

자바 코드는 저장 프로 시저 호출에서 매개 변수를 현재 시스템 날짜와 시간으로 전달합니다.java.lang.NullPointerException을 수정하는 방법

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이 발생합니다.

+0

쇼 전체 코드가 있어야한다고 생각합니다. –

+0

날짜 d = 새 날짜(); Date currentDate = new Date (System.currentTimeMillis() - 3600 * 1000); public String [] [] getDbTable() {int i = 0; \t 문자열 [] [] a = 새 문자열 [3600] [16]; clstmt = con.prepareCall ("exec vcs_gauge 'vs1_bag', 'd', 'date'")); clstmt.setDate ("date", 새 java.sql.Date (currentDate.getTime())); clstmt.execute(); rs = clstmt.getResultSet(); (int j = 0; j <16; j ++) { a [i] [0125] } i ++; } finally {closeConnection(); } return a; } 이것은 자바 코드입니다. SP에는 3 개의 매개 변수가 있고 마지막에는 날짜 유형이 2 개 있습니다. – MES

+0

@ Fumu7 상기 언급 한 내 코드입니다. 내가 배가 고파지기 때문에 새로운 방법으로 알려졌다는 것을 알고 있습니다. – MES

답변

3

먼저 CallableStatement을 만들고 값을 바인딩하십시오. 즉 당신은 NullPointerExceptionnull입니다 clstmt 때문에 당신 prepareCall()까지 얻을

// 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())); 

처럼 문장의 순서를 바꿀 수 있습니다. 편집

나는 당신의 구문이 뭔가

clstmt = con.prepareCall("{call vcs_gauge('vs1_bag', 'd', ?) }"); clstmt.setDate(1, new java.sql.Date(currentDate.getTime())); 

같은 편집이 귀하의 추가 정보를 바탕으로

,

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)); 
+0

내 질문 편집을위한 @Abdullah – MES

+0

@EF 내가 언급 한 것을 수행 할 때 매개 변수 날짜가 저장 프로 시저 vcs_gauge 예외에 대해 정의되지 않았습니다. – MES

+0

@MES 편집 됨. NPE에 관심을 보이고 있지 않았습니다. –

관련 문제