Skip to content
Advertisement

For SQL Server database getting “com.microsoft.sqlserver.jdbc.SQLServerException:The statement must be executed before any results can be obtained.”

I am getting above error when trying to perform insert operation from java application using JDBCTemplate.

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; The statement must be executed before any results can be obtained.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The statement must be executed before any results can be obtained

Advertisement

Answer

Change prepare call to con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement