aspose file tools*
The moose likes Servlets and the fly likes Servlets and JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets and JDBC" Watch "Servlets and JDBC" New topic
Author

Servlets and JDBC

Sam Tilley
Ranch Hand

Joined: Dec 05, 2001
Posts: 160
Hi, i recently passed SCJP which my company decided to reward by throwing me in the deep end of servlets and JDBC (which is a good thing if a little daunting at first). I have over a years experience in Java with a lot of gui but have not encountered servlets and JDBC before (although i have just started servlets1 on cattledrive which is helping).
The project is a trading system and my little project is to use servlets to access a JDBC database and return the results to a webpage, so for example i can query an entry in a database and get all the details on that entry(replacing a asp page doing a similar thing at present) printed up to a web page.
The project is using Forte Community Edition.
Please could someone give me an indication of any good learning materials, the best way to go about setting myself up etc etc, its a bit over my head at the moment and so i am just ploughing through learning material and playing around to try and get it sorted, or if anyone can help guide me through it if they have the time it would be fantastic.
As it is a test of my strength i am keen to make a great job of it (although the timelimit is quite stretchy) without harassing the resident java guru too much.

Thanks in advance


Sam Tilley SCJP, SCWCD
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Sam
There is a good servelet tutorial and also a pretty good one on JDBC topics too.
As far as helping you out that is what we are all here for...
Just post any questions you ahve


Dave
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
I'd also recomment marty hall's core servlet and javaserver pages, it's a pretty good point to start.
cheers


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
John Fontana
Ranch Hand

Joined: Feb 28, 2002
Posts: 235
One good tip I can pass along is to do your Database connections in the init() method of your servlet, as it is expensive on server resources to do on every doGet or doPost request.
Another great resource is Bruce Eckel's "Thinking in Java".


www.websiteandsound.com
"If you do what you've always done, you'll get what you've always gotten."
Sam Tilley
Ranch Hand

Joined: Dec 05, 2001
Posts: 160
Thanks guys, tips like that are always useful i will check out Marty Hall, is there an equivalent of his sort of help for JDBC???
Sam Tilley
Ranch Hand

Joined: Dec 05, 2001
Posts: 160
Hold on ill ask that question in JDBC so i don't cross thread..
[ May 16, 2002: Message edited by: Sam Tilley ]
Val Pecaoco
Ranch Hand

Joined: Dec 05, 2001
Posts: 156
Hi Sam,
Please don't forget to add connection pooling to your app
Ex Animo Java!
-- Val


"Knowledge is power, but enthusiasm is the key." -- Lavern Barn
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Originally posted by John Fontana:
One good tip I can pass along is to do your Database connections in the init() method of your servlet, as it is expensive on server resources to do on every doGet or doPost request.
Another great resource is Bruce Eckel's "Thinking in Java".

Bad idea in modern app servers. Using DataSources (connection pooling) is much faster and less-resource intensive. In fact, doing a "getConnection" from a DataSource at the beginning of your servlet method and then closing it at the end will be significantly faster.
Think about this -- if you get your connections in init() (and presumably store it in a static for each servlet) then each servlet takes up one connection (which is about a Meg of data total). So, if you deploy 100 servlets, you have 100 Meg!
Instead, let the app server do this for you, by using the built-in J2EE connection pooling features.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
and check this to get a free class that implements connection pooling, you will need it... .
cheers
Sam Tilley
Ranch Hand

Joined: Dec 05, 2001
Posts: 160
Cheers guys you have given me some great areas to get started with. I have finally gotten my servlets to work on the Tomcat server using web modules (after some playing around). Now i am getting around to connecting up to my database and should hopefully be bringing in my data soon and using your hints hope that i can create quite a good design.
Thanks for all the good links, does anyone have any good tutorials or resources on Forte (apart from the ones on the Sun site). I thought it was quite a big well used IDE but there seems to be little in the way of good resources or info on it outside Sun.
By the way i am putting all of these links on my site www.coggo.com under java resources so that people (and i) can access them quickly. I am still designing it so it looks better (new menu etc etc) but the aim is to have a good resource center for a lot of these different areas of java (for my own use if no-one else uses it). Servlets has its own little area and will be getting added to quite a bit soon i expect along with JDBC.

Thanks
Sam
 
 
subject: Servlets and JDBC