Breaking News
Home / Java / java.sql.SQLException: No value specified for parameter

java.sql.SQLException: No value specified for parameter

Issue

2011-09-27 23:04:56,739[Thread-15]ERROR SubscriptionXmlService -Failed to query account : java.sql.SQLException: No value specified for parameter 6java.lang.RuntimeException: java.sql.SQLException: No value specified for parameter 6
     at com.infuze.service.subscription.workflow.SyncSubscriptionTrackerWorkflow.executeProcess(SyncSubscriptionTrackerWorkflow.java:130)
     at com.infuze.service.workflow.WorkflowExecutor.execute(WorkflowExecutor.java:24)
     at
Caused by: java.sql.SQLException: No value specified for parameter 6
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
     at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2566)
     at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2542)
     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2389)
     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2333)
     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2318)
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
     at com.infuze.service.subscription.dao.SubscriptionDao.addTracker(SubscriptionDao.java:119)
     at com.infuze.service.subscription.workflow.SyncSubscriptionTrackerWorkflow.executeProcess(SyncSubscriptionTrackerWorkflow.java:91)
     … 10 more

Example Code

public void addTracker(SubscriptionTrackerDto trackerDto) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Exception ex = null;

try {
log.debug(trackerDto.toString());
conn = dataSource.getConnection();
ps = conn
.prepareStatement(“insert into subscription_trackers (created,updated,status,guid,member_id,subscrption_id) values (?,?,?,?,?,?)”);
ps.setTimestamp(1, new java.sql.Timestamp(trackerDto.getCreated().getTime()));
ps.setTimestamp(2, new java.sql.Timestamp(trackerDto.getUpdated().getTime()));
ps.setString(3, trackerDto.getStatus());
ps.setString(4, trackerDto.getGuid());
ps.setString(5, trackerDto.getMemberId());
ps.setLong(5, trackerDto.getSubscriptionId(); // problem is here

ps.executeUpdate();
log.debug(“user registred successfully”);

} catch (SQLException e) {
ex = e;
log.error(“sql error occured while inserting subscription tracker” + trackerDto.getSubscriptionId(), e);
} catch (Exception e) {
ex = e;
log.error(“error occured  while inserting subscription trakcer” + trackerDto.getSubscriptionId(), e);
} finally {
closeDBObjects(conn, ps, rs);
checkException(ex);
}

}

Solution

Check your code and see if the parameter that JDBC driver is complaining about is set or not. For example in the above snippet we set parameter 5 two times instead of setting parameter 6.

[pb_builder]

Leave a Reply