예전에 만들어져 있던 모듈을 수정하다가
쿼리를 추가할일이 있어서 수정했는데 다음과 같은 오류가 발생하였다.
1
2
3
4
5
6
7
8
9
10
|
java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2253)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2233)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2163)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1159)
|
cs |
아 뭐지? 파라미터 갯수도 잘 맞추었는데..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
if (volMsg.hasVariable("host_list")) {
org.json.JSONArray vector_hostList = new org.json.JSONArray(volMsg.getString("host_list"));
for (int i = 0 ; i < vector_hostList.length(); i++) {
JSONObject hostinfo = vector_hostList.getJSONObject(i);
int hostList_cnt = 0;
//INSERT
preparedStatement_hostList.setString(++hostList_cnt, hostinfo.getString("host_name"));
preparedStatement_hostList.setString(++hostList_cnt, date);
preparedStatement_hostList.setString(++hostList_cnt, date);
//UPDATE
preparedStatement_hostList.setString(++hostList_cnt, hostinfo.getString("host_name"));
preparedStatement_hostList.setString(++hostList_cnt, date);
preparedStatement_hostList.addBatch();
preparedStatement_hostList.clearParameters();
}
}
// 실행
preparedStatement_hostList.execute();
|
cs |
보고 또보고
계속 확인 하다 보니
보였다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
if (volMsg.hasVariable("host_list")) {
org.json.JSONArray vector_hostList = new org.json.JSONArray(volMsg.getString("host_list"));
for (int i = 0 ; i < vector_hostList.length(); i++) {
JSONObject hostinfo = vector_hostList.getJSONObject(i);
int hostList_cnt = 0;
//INSERT
preparedStatement_hostList.setString(++hostList_cnt, hostinfo.getString("host_name"));
preparedStatement_hostList.setString(++hostList_cnt, date);
preparedStatement_hostList.setString(++hostList_cnt, date);
//UPDATE
preparedStatement_hostList.setString(++hostList_cnt, hostinfo.getString("host_name"));
preparedStatement_hostList.setString(++hostList_cnt, date);
preparedStatement_hostList.addBatch();
preparedStatement_hostList.clearParameters();
}
}
// 실행
preparedStatement_hostList.executeBatch();
|
cs |
바보같이
preparedStatement_hostList.execute(); 으로 쓴 것이다.
preparedStatement_hostList.executeBatch(); 으로 변경했더니 잘 됐다.
해결 완료!
반응형
댓글