(It seems out of date and possible reason why users ask JDBC questions on list, here is a suggested draft replacment, either way it needs a bit of updateing.)
Struts apps are web applications and use the J2EE resources of the application server (container) and a DB server. A connection pool is provided by your application server and configured by your application server. It requires a JDBC driver be installed and configured with db server IP address, login id and password, size of pool, etc.
Examine the application server documentation.
Once you configure this connection pool you can test it via a Servelt. Ex:
protected void doPost(HttpServletRequest req, HttpServletResponse res) { PrintWriter out = null; Connection conn = null; try { out = res.getWriter(); res.setContentType("text/html");
String foo = "Not Connected to DB"; // test that we have a working Data source and a db Connection Context ctx = new InitialContext(); if (ctx == null) throw new Exception("Boom - No Context");
DataSource ds = (DataSource) ctx.lookup("java:comp/env/bppool");
if (ds != null) conn = ds.getConnection(); if (conn != null) foo = "Got DB Connection " + conn.toString(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from content"); if (rs.next()) { foo = rs.getString(2); } //if stmt.close(); conn.close(); out.println("DB Con: " + foo);
So now you have a working connection pool.
Most people recommend that you use a DAO implementation, and not work at a JDBC level, but there are times and reasons to use JDBC.
There are many popular and good DAO implementations. You need to select how you plan to implement DAO.
The Struts Mail lists mentions Ibatis.com and Hibernate. They both come with excellent documentation.
Some methodologies recommend that you test the DAO in a unit test, before you try to use it in Struts. A DAO that does not update or multi row select outside of Struts, will not start working in Struts, and it might make it harder for you to debug where the potential problem is.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]