Is it possible to run an SQL script that doesn't return a resultSet or is not an INSERT or UPDATE type of script?
I'm trying the following:
Query q = entityManager.createNativeQuery("DECLARE @max int;\n" +
"SELECT @max = MAX(customer_number)+1\n" +
"FROM organisation\n" +
"\n" +
"exec('ALTER SEQUENCE organisation_customer_number_seq RESTART WITH ' + @max)");
...but of course that just creates the query, how to execute it? I can only find getters for different types of resultSets and executeUpdate method for Query. How to just run that query I created above to restart a sequence?
Some of the methods you see in Query
actually execute the query, e.g Query.getResultList :
getResultList()
Execute a SELECT query and return the query results as an untyped List.
List<Object[]> results = q.getResultList();
UPDATE : in your case the query ends up being an ALTER
so as you figured it out, the relevant method will be executeUpdate()
which returns no list or value, but the number of affected rows.
int executeUpdate()
Execute an update or delete statement.
int altered = q.executeUpdate();