I have UPDATE request in Java EE, Postgresql that returning 2 values.
connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
statement = connection.prepareStatement(
"UPDATE system.current_orders SET " +
"status_id = 3, " +
"taken_dt = now(), " +
"system_dt = now(), " +
"driver_car_id_taken = ?, " +
"driver_color_id_taken = ?, " +
"WHERE id = ?" +
"RETURNING aggregator_id, taxi_name_from"
);
statement.setInt(1, driverCarIdTaken);
statement.setInt(2, driverColorIdTaken);
statement.setInt(3,orderId);
resultSet = statement.executeQuery();
while (resultSet.next()) {
aggregatorId = resultSet.getInt("aggregator_id");
token = resultSet.getString("taxi_name_from");
}
how can this be implemented in Spring JDBC to get 2 values in one UPDATE request
As the code already shows, the SQL statement works like a
SELECT
query, hence the use ofexecuteQuery()
.So do exactly the same as you would with a
SELECT
query in Spring JDBC:jdbcTemplate.query(...)
methods.Behind the scenes,
jdbcTemplate.query(...)
creates aPreparedStatement
and callsexecuteQuery()
. It is nothing but a helper class for doing that1. A very powerful helper class, with lots of nice features, but that's essentially all it is.1) and for calling
executeUpdate()
too, or course.