#try with resource

1 messages · Page 1 of 1 (latest)

merry token
#
        try (Connection connection = getConnection()) {
             try (PreparedStatement ps = connection.prepareStatement(
                     """
                                 CREATE TABLE IF NOT EXISTS islands (
                                     id TEXT PRIMARY KEY,
                                     owner_id TEXT NOT NULL,
                                     location_x INTEGER NOT NULL,
                                     location_z INTEGER NOT NULL,
                                     size INTEGER NOT NULL
                                 );
                             """)) {
                 ps.execute();
             }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

this is the first time i've encountered a scenario where i have multiple things that need to be closed. is it better to put both in one try with resource of separate it like what i have here?

wraith ruinBOT
#

<@&987246399047479336> please have a look, thanks.

mint scarab
#

You can have them in teh same try separated by ;

normal glen
#

It's it's the only statement then yes

#

If you're going to execute more statements on the same connection then no

#

Also name SQL tables singularly

#

island

#

Not islands

merry token
#

ty. did not know that