This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JSP and the fly likes Connecting To Database Through web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Connecting To Database Through web.xml" Watch "Connecting To Database Through web.xml" New topic

Connecting To Database Through web.xml

Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
Hi,sorry if this post should be in JDBC instead...but because its directly related to JSP and web.xml i thought it best here.

Anyway, i want my web application to be able to connect to a MySQL database directly through values i set in web.xml. Even though i can connect through a normal java class no problems, i specifically don't want to use a java class or servlet in this instance. Furthermore, I believe this can be achieved solely through web.xml. Perhaps someone could firtsly confirm this?

Here's what i've done so far. In web.xml i have the following:


<param-value> jdbc:mysql://localhost:3306/dbName,com.mysql.jdbc.Driver,username,password </param-value>

I have the mysql connector jar file in tomcat/common/lib.
In my own application folder i have jstl.jar & standard.jar in the lib folder and all required tag libaries in the tld folder.

Any advice or comments on this way of connecting would be greatly appreciated.

Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Its perfactly fine to define DB connection strings in web.xml. But it is discouraged to JSTL SQL tags in a production application. JSTL SQL tags are usually used for prototyping stuff. Best practices are to seperate the DB access code from presentation tier.

It is sorta covered in the JavaRanch Style Guide.
subject: Connecting To Database Through web.xml
jQuery in Action, 3rd edition