6 Replies Latest reply: Nov 21, 2007 7:48 AM by 807603 RSS

    database connections

    807603
      hi

      in how many ways can we use database connections using JSP.

      Thank u
        • 1. Re: database connections
          807603
          3.

          It is hard to give a specific answer to a non-specific question.
          • 2. Re: database connections
            807603
            First rule, don't do it in JSP since they are supposed to be used in the presentation layer not in the bussiness layer. Hava a servlet do that at the very least. The best you could have, is a JNDI resource which would manage connection pooling to you for free.

            Best Regards,

            MeTitus
            • 3. Re: database connections
              807603
              hi
              thank u for ur response
              can write all the database connection and queries in a bean and we can call that bean in our jsp file...
              • 4. Re: database connections
                807603
                sowji wrote:
                hi
                thank u for ur response
                can write all the database connection and queries in a bean and we can call that bean in our jsp file...
                That is a better design, especially if your bean has setters and getters that are linked to a JSP form. I have done a similar application.
                • 5. Re: database connections
                  807603
                  sowji wrote:
                  hi
                  thank u for ur response
                  can write all the database connection and queries in a bean and we can call that bean in our jsp file...
                  Yes as maple shaft mentioned. I would add that it's still a good idea to have a servlet in between the jsp and the bean.

                  Accessing the bean directly in the jsp still has you doing bean tags or scriptlet. The servlet gets called by the submit and is much tidier in my opinion.

                  PS.
                  • 6. Re: database connections
                    807603
                    yes use a severlet and then create a datbase bean... This will ensure you only have one connection to the database, best cod of practise really.

                    If you need more help see the MVC modle