Including file in Servlet

I want that despite writing repeatedily the code for db connectivity I should make one file and just include it to my each servlet file to connect dbplz help
[171 byte] By [farakha] at [2007-10-3 9:48:00]
# 1
I mean to say like java script or CSS we put whole code in one file and link them into htmllike that I need that we should keep the db connectivity codes in one file and link/reuse
farakha at 2007-7-15 5:05:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
By connectivity, do you means the opening of the connection to the db or the querying of the db?Keep hope, there are great solutions for each of then :)
alban.maillerea at 2007-7-15 5:05:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Do you mean storing the connection parameters in a file and using it in servlets repeatedly?

If that is the case then you should use Properties class.

Properties p = new Properties();

p.load(new FileInputStream("db.properties"));

Class.forName(p.getProperty("driver"));

Connection con=DriverManager.getConnection(p.getProperty("url"),p.getProperty("user"),p.getProperty("password"))

store the properties in a file as

driver=

url=

user=

password=

qatadaa at 2007-7-15 5:05:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> Do you mean storing the connection parameters in a

> file and using it in servlets repeatedly?

> If that is the case then you should use Properties

> class.

> Properties p = new Properties();

> p.load(new FileInputStream("db.properties"));

> Class.forName(p.getProperty("driver"));

> Connection

> con=DriverManager.getConnection(p.getProperty("url"),p

> .getProperty("user"),p.getProperty("password"))

> store the properties in a file as

> driver=

> url=

> user=

> password=

thanks for your reply

this code even bigger than db connecting code so why I use this if I have to spend the same time

Can v make a file and import it or other solution

farakha at 2007-7-15 5:05:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
ever heard about functions?
alban.maillerea at 2007-7-15 5:05:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
alban.maillereI made a package but frankly don't know how to use it ? plz help
farakha at 2007-7-15 5:05:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
At this point , I can't be of any help, sorry... please teach yourself about object oriented programming
alban.maillerea at 2007-7-15 5:05:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Sorry, I was kidding
farakha at 2007-7-15 5:05:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...