Results 1 to 1 of 1
  1. #1
    Tirka is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default passing a db connection across jsps throughout a session

    hi all,
    please,i need urgent help with this:

    i have this database connection bean DBConnection.java

    package common;

    import java.io.*;
    import java.sql.*;
    import java.util.*;

    public class DBConnectionBean
    {

    private String url = ("jdbc:oracle:thin:@localhost:1521:ASEB");
    private String user = "cmc";
    private String pass = "orapower2223";
    Connection conn = null;

    public DBConnectionBean(){
    try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(url,user,pass);
    }
    catch(Exception e){e.printStackTrace();}
    }// End Constructor

    public Connection getConnection(){
    return conn;
    }
    }


    And in my first,i.e, Start.jsp i use

    <jsp:useBean id="conid" class="common.DBConnectionBean" scope="session"/>

    and:
    Connection con = conid.getConnection();

    Now i got this:
    Because i've put the Bean into session scope, i shouldn't call the getConnection() method on the second page or any subsequent pages.

    Calling getConnection only once, to instantiate the connection, then simply relying on the session scope of the Bean to maintain that connection would do.

    The PROBLEM is: how exactly is it done (the code)?;
    how do i use the connection bean in any subsequent jsp pages?
    Plz help..
    Last edited by Tirka; 07-20-2009 at 08:03 AM.

Similar Threads

  1. Replies: 1
    Last Post: 04-21-2009, 11:20 PM
  2. Replies: 2
    Last Post: 12-23-2008, 06:35 PM
  3. Design Editor For JSPs
    By jazz17782 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 01-12-2008, 12:52 AM
  4. jsps with html
    By gayatridevi in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-31-2007, 12:42 PM
  5. jsps with html
    By gayatridevi in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-19-2007, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •