This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes need an advice in JDBC coding !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "need an advice in JDBC coding !!" Watch "need an advice in JDBC coding !!" New topic

need an advice in JDBC coding !!

Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37
Hai All,

I need an advice in JDBC coding !!

In my project i need to write a servlet which parses an XML,
retrieves values of XML and invokes stored procedures using those values.

My servlet uses a Parserclass method
Map parsexml(string str) to parse the data. This method parses the data and return the parsed values as a HashMap.

My problem is ... i am not sure where to include my JDBC code to execute the stored procedures.

1) Should i write the jdbc logic in a method of the parserclass itself
2) should i write one more class which takes care of jdbc stuff
3)should i include the jdbc code in servlet.

I am using weblogicServer8.1 for the application and jdbc connection pool inorder to get the connection object.
I think if i have to use some other class to handle jdbc stuff, i should be passing this connection object to other class


I would like to know whether my approach is correct or not.
What would be the best approach in my cenario.
I am not able to properly judge as i am new to this.

Any help is appreciated,
Thanks in advance,
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32636

I would go with option 2. It keeps the JDBC as separate as possible. Why would you need to pass the class a connection, rather than have the JDBC class get the connection itself?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37
Hai Jeanne Boyarsky

You are rite, there is no need to pass connection object as well.
I will obtain it in the JDBC class.

Thanks for ur advice.
I appreciate ur help
I agree. Here's the link:
subject: need an advice in JDBC coding !!
It's not a secret anymore!