I use h2 database 1.4.195. I am writing a request:

String selectFriends = "SELECT * FROM " + ACCOUNT_TABLE_NAME + " JOIN(SELECT friendId FROM " + FRIENDS_TABLE_NAME + " WHERE accountId = ?) AS tbl ON " + ACCOUNT_TABLE_NAME + ".id = tbl.friendId;"; try (PreparedStatement statement = this.connection.prepareStatement(selectFriends)) { statement.setLong(1, id); try (ResultSet resultSet = statement.executeQuery()) { resAccount.setFriends(createFriends(resultSet)); } } catch (SQLException e) { e.printStackTrace(); } private List<Account> createFriends(ResultSet resultSet) throws SQLException { List<Account> friends = new ArrayList<>(); while (resultSet.next()) { friends.add(createAccountFromResult(resultSet)); } return friends; } 

The temporary table tbl is underlined at compile time.

Here is the entire stack trace: enter image description here

  • rewrote the query "select * from accounts accounts id in (select friendId from where your whereId =?);"; It works, but it would be interesting to find out what the problem is, I could not really google it. - diofloyk
  • there is little source code and the spectra is not all, it is difficult to study the cause of the error - DaysLikeThis
  • @Visman Thank you, right, should be database - diofloyk
  • @DaysLikeThis added the source code, laid out the stack trace, an error in the PreparedStatement line. I think it's just impossible for some reason to create a statement from such an sql query. Although it seems to be quite typical. ) - diofloyk
  • Try * to replace with the names of the necessary columns, judging by the stektraus error parsing the stetement. Also found a request for a bug groups.google.com/forum/#!topic/h2-database/X_R-jt5FMvc - DaysLikeThis

1 answer 1

The parser could not process the wildcard (*) in the request. Replace it with real column names or names with aliases.