Breaking News
Home / Java / Java Issues / Can not issue executeUpdate() for SELECTs

Can not issue executeUpdate() for SELECTs

Exception

2011-09-27 23:02:52,088[Thread-22]ERROR SubscriptionXmlService -Failed to query account : java.sql.SQLException: Can not issue executeUpdate() for SELECTs
java.lang.RuntimeException: java.sql.SQLException: Can not issue executeUpdate() for SELECTs
at com.infuze.service.subscription.workflow.SyncSubscriptionTrackerWorkflow.executeProcess(SyncSubscriptionTrackerWorkflow.java:130)
at com.infuze.service.workflow.WorkflowExecutor.execute(WorkflowExecutor.java:24)
at com.infuze.service.subscription.xml.SubscriptionXmlService.syncTracker(SubscriptionXmlService.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Caused by: java.sql.SQLException: Can not issue executeUpdate() for SELECTs
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.executeUpdate(PreparedStatement.java:2373)

 

Example Code

public SubscriptionDto getSubscription(String subscriptionGuid) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Exception ex = null;

SubscriptionDto subDto = null;
try {
log.debug(“subscription guid” + subscriptionGuid);
conn = dataSource.getConnection();
ps = conn
.prepareStatement(“select id,created,updated,access_token,token_secret,status,guid,service_id from subscriptions subs where subs.guid = ?”);
ps.setString(1, subscriptionGuid);

ResultSet rst = ps.executeQuery();
while (rst.next()) {
subDto = new SubscriptionDto();
subDto.setId(rst.getLong(“id”));
subDto.setCreated(rst.getDate(“created”));
subDto.setUpdated(rst.getDate(“updated”));
subDto.setAccessToken(rst.getString(“access_token”));
subDto.setAccessTokenSecret(rst.getString(“token_secret”));
subDto.setStatus(rst.getString(“status”));
subDto.setGuid(rst.getString(“guid”));
subDto.setServiceId(rst.getInt(“service_id”));
}

ps.executeUpdate(); //  problem is here

log.debug(“tracker updated successfully”);

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

return subDto;
}

Solution

Check your code , for example in the above snippet we should be calling

ps.execute() and not ps.executeUpdate() as the sql is a select  and not an insert/delete/update.[pb_builder]

Check Also

Data truncation: Data too long for column – JDBC

Issue Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column ‘columname‘ at row 1     …

Leave a Reply