File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
JDBC and Relational Databases
Joined: May 09, 2005
Aug 24, 2005 04:02:00
I am maintaining a project on
database is mysql.
I have a connection instance variable con.
I am using the same connection in many methods. (The code is below just typed one of the methods for explanation)
Is this the correct way to use the connection object in all the methods
or should i have seperate connections in all the methods ?
I have observed that the page does not get properly loaded if i use the instance variable con in all the methods.
But if i open and close connections in all the methods there will be lot of overhead so can anyone suggest a better way...
public class DCRDoctorData extends
public void doGet(
con = ConnectionHandler.getConnection(dbname);
private void add1()
Statement stmt = con.createStatement(); // using the instance variable
Joined: Apr 14, 2004
Aug 24, 2005 04:12:00
You probably want to use Connection Pooling, get a connection everytime you need it and close it in finaly block when you are through using it.
subject: Connection Object
java.sql.SQLException: Closed Connection
Database Access Design
Returning DB connection
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015