jdbc software architecture design, best practice
- From: "anselm" <anselm.waigand@xxxxxxxxxxxxxx>
- Date: 25 Oct 2006 02:17:51 -0700
hi all,
I hadn't used any jdbc for some time, but I had to come back at it most
recently. so I dug out some code of mine which I had used a few years
ago - both mysql (which I'm using) and jdbc connector have evolved
somewhat in the meantime. probably a good thing.
it also made me rethink the way I used to structure my applications. I
would encapsulate the code I'd need to set up the query strings, the
code needed to get the database connection and the code needed to
execute the queries themselves in different classes. ideally, I'd have
a few separate utility type classes that I can reuse at some point.
after executing a query, I'd get back a resultset and in my previous
apps, I'd just returned this resultset to the calling method, to then
display it to the user or do some further processing.
maybe I was just lucky or the API was just very forgiving - I now get
errors, indicating that a closed resultset is being read from (or
attempted to be read from). I looked in up in the docs, and yes, a
resultset is automatically being closed when either (or both) the
connection or the exectuting statement are being closed. and because an
unused open connection is bad thing (suposedly), I had always closed
any connection right after statement execution and then passed the
resultset on. wel, not anymore.
what is best practice in this case? read out all necessary data right
in my utility class? possibly writing it to a hashtable, enum or some
other type of suitable container and then passing that on?
a workaround I've been using for now is to leave the connection open
somewhat longer, but I'm not really pleased with it.
well, I'd appreciate some expert tips on this, thanks a lot!
anselm
.
- Prev by Date: Re: connection on application initialisation
- Next by Date: Stopping Oracle stored procedure from the Java code
- Previous by thread: connection on application initialisation
- Next by thread: Stopping Oracle stored procedure from the Java code
- Index(es):
Relevant Pages
|
|