My General Question is: Is it inefficient/bad practice to call preparedStatement.executeBatch() if there’s only one query in the batch?
I’m writing a generic method for the Java Helper Library to execute a query. There’s a javabean called HelperQuery which holds a list of arrays another javabean called QueryParameter which holds a type (like STRING, BLOB, INT, etc.) and a value. The QueryParameter is used to fill the HelperQuery‘s PreparedStatement. In many cases, there will be only one array of QueryParameters.
My Specific Question is: Should I handle things differently if there’s only one array of QueryParameters or would it be ok to handle things exactly the same regardless of how many QueryParameters there are?
executeBatchis a “super” method from thePreparedStatement‘s parentStatementwhich returns anint[]which indicates the success/failure of the executed queries andexecuteQueryreturns aResultSet. Therefore, it would be a good idea to have the two be totally different method calls so the developer can handle them differently. I would recommend:executeQuery(HelperQuery helperQuery)method which will return the associatedResultSetand will only get the firstQueryParameters from theHelperQuery(for convenience) and another method which the developer can specify whichQueryParameterset to use (either have them specify a number of theQueryParameterlist or just pass in theQueryParameters explicitly (I recommend the second of the two)).executeBatch(HelperQuery helperQuerymethod which will return theint[]and the developer can handle that as they wish.It’s always good to give the user (developer in this case) power to do what they want (but also provide for a simple solution for them to perform common tasks).