Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Struts and the fly likes how to to connect to a database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to to connect to a database?" Watch "how to to connect to a database?" New topic

how to to connect to a database?

Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
How do I connect to a database say oracle using Struts & perform some inserts?Any code plz?
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
You go about doing this from Struts the same way you would any other web application. You could use connection pooling or create a connection directly from the JDBC driver.

Matthew Phillips
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17038

Maybe someday I'll get the annotated version of the website I published recreated. The guy who wrote Slapper worm did us a big favor -- NOT!
Anyway, here's code for struts-config.xml:

This is used to build a database connection pool by the Struts ActionServlet, which can then be referenced by the Action processors (via parent member "servlet" or the getServlet() method). The ActionServlet has a set of methods you use to get the connection from the pool. In most cases, you can use the one that requires no parameters.
[ December 18, 2002: Message edited by: Tim Holloway ]
... and how DO you turn off the graemlins when you want a ":" and a "p" next to each other without spacing? I thought the CODE tag was supposed to handle that!
[ December 18, 2002: Message edited by: Tim Holloway ]

An IDE is no substitute for an Intelligent Developer.
It is sorta covered in the JavaRanch Style Guide.
subject: how to to connect to a database?
It's not a secret anymore!