Results 1 to 4 of 4
  1. #1
    evermore is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default JDBC that multiple methods will use

    i need to use JDBC for my java application to connect to database

    but in my application i will have multiple methods (at least 25) that will perform different query and insert different data into my database

    what is the best way to do this, instead of having to establish connection 25 times at beginning of everyone of my methods




    public class MyApplication
    {


    // i was thinking of doing connection here, then in each of my method i just
    do prepare statement and execute query


    public static void main......

    // method1
    ..
    .
    .
    .
    .//method n


    } // of MyApplication



    however i run into error implementing this ( illegal start of expression)
    i was thinking i just declare it at the top so all my method can have access to it....

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Use a connection Pool and maybe a static method for retreiving a connection from that pool so you can condense those three lines of code down to one in other methods, if you feel the need.

  3. #3
    evermore is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default

    srry can u write me a quick sample?
    i have never head of connection pool before

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

Similar Threads

  1. Replies: 3
    Last Post: 02-02-2010, 02:33 PM
  2. Replies: 5
    Last Post: 07-18-2008, 05:30 PM
  3. Replies: 0
    Last Post: 04-01-2008, 11:17 AM
  4. Replies: 0
    Last Post: 09-28-2007, 01:56 PM

Posting Permissions

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