Results 1 to 3 of 3
  1. #1
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Lightbulb Connection to data base

    Hello, I have a class that allows me to establish a connection with a data base and I have other classes singleton that uses the first that I described obtaining a connection. By each method in which I use the connection, first I open the data base, I use it and thenI close it.

    Something like this:

    Java Code:
    Connection conn = new Connection ();
    
    conn.openBase();
    
    .............. something of code....... 
    
    conn.close();
    This works, simply I want to know if it is correct to do it in this way, or if it is possible to improved it.

    Daniel :o

  2. #2
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default

    hello! you could use singleton pattern, hereby you avoid, ( in case of having 500 users), to have 500 objects Connection thing that waste memory.

    Albert

  3. #3
    Eric is offline Senior Member
    Join Date
    Jun 2007
    Posts
    111
    Rep Power
    0

    Default

    If it is an application Web, and it is going to have many consults. I advise to you to read a little of Connection Pool to increase the performance and make the system more robust from the point of view of the concurrent consultations…
    The code that you showed didn't say a lot, because you encapsulate everything in Connection. of which there are no details…

    Eric

Similar Threads

  1. no connection
    By even in forum JDBC
    Replies: 15
    Last Post: 01-02-2008, 02:50 PM
  2. Problems with Jtable connected to data base
    By elizabeth in forum AWT / Swing
    Replies: 2
    Last Post: 08-07-2007, 05:24 PM
  3. Replies: 1
    Last Post: 08-06-2007, 06:38 PM
  4. 2 threads sharing a data base connection
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 05:41 AM
  5. Data Source :How to get connection inside java
    By peiceonly in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-02-2007, 11:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •