If I have a sequential action, spread over multiple methods, that makes very many SQL Queries, does it make sense to pass the Statement object to the different methods instead of passing the Connection and calling createStatement() every time?
Could you provide more details , like what kind of sequencial operation you are doing in your code, are all those operation are insert or mixed operation of insert/update. whether they are on same table or multiple tables ?
in my view spanning one conection /statement to multiple places makes maintainance difficult in long run. It also make debugging process long.
I would rather prefer collect all queries at one place and execute them.if possible I would use addBatch() of prepared statement if operation is on same table.
Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
For advanced transaction processing, better see JTA. [ May 04, 2005: Message edited by: Adeel Ansari ]
Joined: Dec 13, 2004
Thanks for replies!
All of the actions are read-only queries, and at the moment at least it is assumed that none of the information being queried will be changed while the queries are in progress, so transactions are being ignored. I cannot do a batch because subsequent queries depend on the results of the prior queries.
What I am actually doing is building an XML file (using JDom) based on the contents of the database whose schema that models a tree-type hierarchy. A single table contains all of the parent-child relationships for every tree in the database. The
Element createElement(Connection conn, String id, String tableName)
method creates an Element (JDom's version of Node) with attributes populated by "SELECT * FROM <tableName> WHERE ID = <id>". Then recursively calls createElement() with the identifiers and table names that the relationship table lists for this element's children, and adds those elements to the content of the current one.
So I'm wondering if it maybe be more efficient to pass the Statement instance, instead of the Connection instance.