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.
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".
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
and check this to get a free class that implements connection pooling, you will need it... . cheers
Joined: Dec 05, 2001
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.