1. Problems:
When multiple select queries are used for union, the SQL error message is as follows
### Cause: java.sql.SQLException: The used SELECT statements have a different number of columns
; bad SQL grammar []; nested exception is java.sql.SQLException: The used SELECT statements have a different number of columns
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
2. Solutions
This is because the table structure of the records generated by the two SQL statements using union is inconsistent. Only the records set with completely consistent structure can use union. The above is caused by the different fields of the two tables, so you can check and solve it
Similar Posts:
- java.sql.SQLException: Error; uncategorized SQLException; SQL state [null]; error code [0];
- C# Unable to translate set operation when matching columns on both sides have different store types
- APP Report DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null, DRIVER=4.17.29
- java.sql.SQLException: Got error 28 from storage
- FAQ 66: java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
- [Solved] gbase8s Error: Caused by: java.sql.SQLException: Transactions not supported
- java.sql.SQLException: Fail to convert to internal
- The jdbc driver imported from idea into MySQL appears “Java. Lang. classnotfoundexception: com. Mysql. CJ. JDBC. Driver”
- FAQ 57: java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
- [Solved] java.sql.SQLException: Access denied for user ”@’localhost’ (using password: NO)