File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets and JDBC

 
Sam Tilley
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd also recomment marty hall's core servlet and javaserver pages, it's a pretty good point to start.
cheers
 
John Fontana
Ranch Hand
Posts: 235
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Sam Tilley
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 156
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,
Please don't forget to add connection pooling to your app
Ex Animo Java!
-- Val
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and check this to get a free class that implements connection pooling, you will need it... .
cheers
 
Sam Tilley
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic