says that you can't do it (so it is not possible) and other people that says you can do it with no problems,
for your information i have used the same statement for multiple queries, but i wonder if there's any problem
or issue with that.
This builds a query that ends up looking somethign like this:
query = "UPDATE schema.table SET col1= 'John', col2 = 'Doe' WHERE col3 like 'Boston';";
Did I answer your question?
I use this method when querying databases with SELECT statements. I pass many different types in without any problems. If you wanted to change it to handle UPDATE/CREATE statement change statement.executeQuery(query); to statement.executeUpdate(query) and return something besides a ResultSet. Try and reuse code as much as possible. Hope this helps.
I've used this class for multiple queries in the same class and it has worked.
But i was wonder if there's any issues with that.
THIS CODE IS A PART OF WHAT I'M WORKING ON
this link might help more.
is that i would've to create more than a preparedstatement to do multiple queries. Because
a preparedstatement asks me for the sql and inmediatly compiles itself.
Of course you would have to use different ResultSets
By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.
You can do
In that loop, using a Statement is not efficient, because it's compiled again and again, which is a costly operation. Use PreparedStatement as advised above - it's more efficient.
Also overall you can do some code improvements. Whenever using JDBC, ensure that Results, Statements and Connections are close()d in a finally block.
This ensures that all your JDBC resources are cleaned up even if there's an exception. The Resultset close()s are, strictly speaking, not necessary because statement.close would close them anyway; but it's good practice.>