Made a mistake again.
Fight for no next time.
Even if you do it again, you need to know where to find the answer.
So, take a note and take a look at the alert.
Error
When querying data using JdbcTemplate, an exception occurs:
PreparedStatementCallback; Bad SQL grammar [--sql--]; Nested exception is java.sql.SQLException: Invalid column name
The code is roughly as follows:
1list<someobj> list =getjdbctemplate (). query (SQL,2 NewRowMapper () {3 PublicObject Maprow (ResultSet arg0,intarg1)4 throwsSQLException {5Someobj row =Newsomeobj ();6 7Row.setid (arg0.getstring ("ID"));8 9 returnRow;Ten } One});
Find the wrong
Since the column name is invalid , it must be a SQL issue.
As a result, the SQL posted to the PL/SQL execution, strange, no error.
Anti-second interview several times, are the program error, but directly execute SQL no problem.
Recall the previous problem because of the number of parameters, encountered such an exception: Java.sql.SQLException: Invalid column index.
So I checked the parameters again, no problem.
Can only search the Internet to find the answer.
Searched several articles, did not find and this similar question.
Looking at it, it suddenly occurred to me that the columns queried in SQL are consistent with the columns in the Java code to get them?
It turns out that.
The reason for the exception was found: There are no queries in SQL for the columns used in Java code.
That is, Java uses code like this: Row.setid (arg0.getstring ("Col_a")) , and the SELECT statement in SQL does not col_a this column.
PostScript: This is the adjustment of the previous code, the removal of some unnecessary columns, so that the SQL and the subsequent need to value the column inconsistent.
This problem should not arise in the new development.
Because such applications generally determine which columns are required and then assemble the SQL.
Querying data with JdbcTemplate error: Invalid column name (resolved)