#java.sql.SQLException: statement is not executing

11 messages · Page 1 of 1 (latest)

eternal badger
#
try(Connection connection = getConnection()){
            PreparedStatement ps = connection.prepareStatement("INSERT INTO TradableItem (id, shopSubCategory) VALUES(?, ?)");
            for(TradableItemJson tradableItem : tradableItems){
                PreparedStatement query = connection.prepareStatement("SELECT id FROM Items WHERE uniquename = ?");
                query.setString(1, tradableItem.uniquename);
                ResultSet result = query.executeQuery();
                result.next();

                var itemId = result.getInt("id");
                var shopsubcategory = ShopSubCategory.fromString(tradableItem.shopsubcategory).getId();

                ps.setInt(1, itemId); // this throws the exception 
                ps.setInt(2, shopsubcategory);
                ps.addBatch();
            }
            ps.executeBatch();
            connection.commit();
        }
        catch (Exception e){
            return false;
        }
        return true;
spring sundialBOT
#

This post has been reserved for your question.

Hey @eternal badger! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

eternal badger
#

For whatever reason this keeps throwing an exception and i cant figure out why

jovial moon
#

I'd recommend including the exception

eternal badger
#

java.sql.SQLException: statement is not executingthats the whole exception im getting

#

when i hardcode the value it works

#

it just makes 0 sense for it not to work when a function return a value

#

and the function does return a value (1, 129) to be exact