Results 1 to 4 of 4
- 03-16-2010, 05:16 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 8
- Rep Power
- 0
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....
- 03-16-2010, 07:07 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 03-16-2010, 07:20 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 8
- Rep Power
- 0
srry can u write me a quick sample?
i have never head of connection pool before
- 03-16-2010, 07:27 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
JDBC problem with multiple resultsets on mysql database: getUpdateCount() always zero
By plica10 in forum JDBCReplies: 3Last Post: 02-02-2010, 01:33 PM -
text box listeners and returning multiple strings from methods
By int80 in forum New To JavaReplies: 5Last Post: 07-18-2008, 04:30 PM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By Java Tip in forum Java TipReplies: 0Last Post: 04-01-2008, 10:17 AM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks