If I only ever use one Statement at a time would it be worthwhile cacheing it along with my Connection. I already cache the connection so I could cache the statement at almost no cost at all.
Essentially I suppose I am asking if there is any cost/overhead to creating a statement. I fully understand the benefits of creating prepared statements. I am talking specifically about Connection.createStatement() here.
Some research into an open-source jdbc driver (jtds) suggests the following object overhead for each Statement created. I am trying to count the cost of creating a new
Statementevery time I want to query the database rather than holding one single cached one and reusing it:Connection– Presumably cached so insignificant.TdsCore– Looks like a protocol implementation but it is cached so insignificant.ResultSet.ArrayListof batched items.ArrayListof openResultSets.So it looks like the highest proportion of the cost of
Statements involves what is left around by any query that has been run.