Arraying Arraying - 1 year ago 88
Java Question

Close MySQL execute() query in Java

Okay, so I have the following code:

Statement statement = connection.createStatement();
boolean resultSet = statement.execute("INSERT INTO guilds(`ID`, `Prefix`, `Join`, `Leave`, `EnableRoles`, `Role`)"
+"select col1, col2, col3, col4, col5, col6"
+"from (select '"+id+"' as col1, '//' as col2, 'Welcome, {user}!' as col3, 'Goodbye, {user}!' as col4, 'false' as col5, 'none' as col6) t"
+"WHERE NOT EXISTS (SELECT * FROM guilds WHERE ID = '123');");

Usually, when you do executeQuery(); you have a resultSet.close(); method.

I was wondering if there is one for execute() (didn't seem to pop up on IDE) and if not, if/how you close it like resultSet.close();


Answer Source

Just close the statement statement.close();

Also it would be good to place everything in try catch block and perform closing in finally clause.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download