D
D
deathmurder2020-05-12 23:18:11
Java
deathmurder, 2020-05-12 23:18:11

How to resolve an error when executing a nested SQLite query?

Throws an Exception when executing the request. Can't find column "Nizhny" although Nizhny-Novgorod comes to cityName

public static void setCityIdToOrderByName(String cityName, int orderId) throws SQLException {
            preparedStatement = connection.prepareStatement("UPDATE orders SET city_id = (SELECT c.id FROM city c WHERE c.name = " + cityName + ") WHERE id = " + orderId);
            preparedStatement.executeUpdate();
    }


org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: Lower)
at org.sqlite.core.DB.newSQLException(DB.java:941)
at org.sqlite.core.DB.newSQLException(DB .java:953)
at org.sqlite.core.DB.throwex(DB.java:918)
at org.sqlite.core.NativeDB.prepare_utf8(Native Method)
at org.sqlite.core.NativeDB.prepare(NativeDB.java :134)
at org.sqlite.core.DB.prepare(DB.java:257)
at org.sqlite.core.CorePreparedStatement.(CorePreparedStatement.java:47)
at org.sqlite.jdbc3.JDBC3PreparedStatement.(JDBC3PreparedStatement.java: 30)
at org.sqlite.jdbc4.JDBC4PreparedStatement.(JDBC4PreparedStatement.java:19)
at org.sqlite.jdbc4.JDBC4Connection.prepareStatement(JDBC4Connection.java:35)
at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:241)
at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:205)
at service.SQLhandler.setCityIdToOrderByName(SQLhandler.java:321)
at bot. BotState$2.handleInput(BotState.java:54)
at bot.Bot.onUpdateReceived(Bot.java:87)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1510)
at org.telegram.telegrambots. meta.generics.LongPollingBot.onUpdatesReceived(LongPollingBot.java:27)
at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:305)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-05-12
@deathmurder

Well, quotation marks.
... WHERE c.name = '" + cityName + "') ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question