I think that it is bad practice to to database connection inside the jsp page. Make a seperate bean or different class that handles the connection will help you in long run.
-----Original Message----- From: Thorbjørn Ravn Andersen (Scandiatransplant) [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 29, 2002 10:14 AM To: [EMAIL PROTECTED] Subject: Struts DataSource object - how much can be taken for given? I have now progressed further, and run into a few questions which I would appreciate help with in order to be nudged in the right direction. After a bit of work with the Struts basic JDBC-connection pooling system and the struts-config.xml file, I found out that I can get access to my database from a JSP as follows: <%@ page import="javax.servlet.*,javax.sql.*,java.sql.*,org.apache.struts.*,org.a pache.struts.action.*" %> <% DataSource dataSource = (DataSource) getServletContext().getAttribute(Action.DATA_SOURCE_KEY); Connection conn = dataSource.getConnection(); Statement s = conn.createStatement(); ResultSet rs = s.executeQuery( "select count(*) from recipient"); ... I want to do this in order to provide a set of JSP-pages which test basic functionality without requiring the whole MVC-system to be functional. I have written a couple of beans, each of which are to correspond to a given database table (not much new in that), where they will synchronize over a Connection-object, and I would like to know how I should design this for it to be so generic as possible. The existing database scheme we are building this application on top, consists of several hundred tables, so I must recycle resources. Can I expect that the DataSource object will be the same in the lifetime of my application (a given bean will only talk to a single database, and we will most likely not use more than a single database for the whole application), or should I look in getServletContext() each time I need a new Connection? I understand that for connection pools to work correctly I should close my connection when I am done with it, and request a new one next time. Will the above code allow me to choose connection pool managers freely (provided that it is running correctly), or is this just for the one provided by Struts? I have a strong feeling that I should refrain as much as possible from scriplets in the JSP, so I would also appreciate knowing if there are beans or taglibs that help manage such an object. My own beans will be able to accept the appropriate object (DataSource etc) as a property, but are there any facilities that help providing what I need as a property? And a last question. As part of the work flow of the users they may have to be presented to a rather long list of persons. I have considered whether it would be feasible ressourcewise to simply build an ArrayList of Beans, where each bean corresponds to a person in the database, and then have it as a session property. This also goes very well with the display:table taglib. Should I go for a database request per subtable, and do it all by my self? I would appreciate comments from people who have tried this, and have experiences to share. Some of the tables have many fields, and may be rather large objects. We can expect few users, and few simultaneous searches. If I have missed a FAQ where this is explained in detail, I apologize. I am still struggling with learning the framework, and I have tried to follow and read most of the documentation and the links it contains. Best Regards, -- Thorbjørn Ravn Andersen Scandiatransplant, c/o Christian Mondrup 89 49 53 01 http://biobase.dk/~tra -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>