Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   JDBC question (http://www.programmingforums.org/showthread.php?t=13050)

metsfan Apr 24th, 2007 1:23 PM

JDBC question
 
I am currently making a website using java with tomcat

As anyone who has used tomcat/servlets knows, each java page gets called every time you run a new page. My problem is that i have a page which uses a database, and every time i run the page, it has to reconnect to the database. is there any way to make it so that the connection is "open", that is no matter how many times i go to this page, i never have to reconnect.

BTW, i am using postgresql and JDBC v.4

paulchwd May 21st, 2007 5:20 PM

Well if you are using a servlet you could handle the connections in the init() method which is called only once in the servlets life (when it is first accessed) but that is not wise, it is better to do any database connections in the doPost() / doGet() methods

msi_333 May 29th, 2007 12:58 PM

connection
 
I think that you have to connect to the database every time , because the "connection" object needed in every servelts page and you should close the connection to the database when u finish ur query in the page and also close the statement object ... using the close() function. I don't know why u considered it as a problem .:confused:


All times are GMT -5. The time now is 2:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC