try(PreparedStatementps=connection.prepareStatement("Put SQL here")){
try(ResultSetrs=ps.executeQuery()){
// Do something with ResultSet
}
}catch(SQLExceptione){
// Handle exception
e.printStackTrace();
}