Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 14th, 2004, 11:18 AM
Registered User
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connecttion Pool issues - Sample App

Hello,
I'm having problems getting my connection pool to initialize in the sample app in chps. 19-20.

I have it set up similar to how the book describes and I cannot get past this error:
java.lang.IllegalStateException: Pool not initialized.
     at com.harrisalternatives.struts.util.ConnectionPool. getInstance(ConnectionPool.java:33)

I'm using the com.mysql.jdbc.Driver instead of the one in the book and the BasicDataSource instead of the GenericDataSource in my DBInitServlet class, but everything else is the same.

Can anyone help me? Below are snippets of my code:

*web.xml:
<servlet>
        <servlet-name>dbInit</servlet-name>
        <servlet-class>com.harrisalternatives.struts.util.DBInitSer vlet</servlet-class>
        <init-param>
            <param-name>driverClass</param-name>
            <param-value>com.mysql.jdbc.Driver</param-value>
        </init-param>
        <init-param>
            <param-name>jdbcURL</param-name>
            <param-value>jdbc:mysql://10.10.10.4:3306/testdb</param-value>
        </init-param>
        <init-param>
            <param-name>minCount</param-name>
            <param-value>1</param-value>
        </init-param>
        <init-param>
            <param-name>maxCount</param-name>
            <param-value>10</param-value>
        </init-param>
            <init-param>
            <param-name>username</param-name>
            <param-value>tomcat</param-value>
        </init-param>
        <init-param>
            <param-name>password</param-name>
            <param-value>tomcat</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

public class DBInitServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
    try {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(getInitParameter("driverClas s"));
        ds.setUrl(getInitParameter("jdbcURL"));
        ds.setMaxActive(Integer.parseInt(getInitParameter( "maxActive")));
        ds.setMaxWait(Integer.parseInt(getInitParameter("m axWait")));
        ds.setDefaultAutoCommit(false);
        ds.getConnection();
        ConnectionPool.init(ds);
    } catch (SQLException e) {
        e.printStackTrace();
        throw new ServletException("Unable to open datasource");
        }
    }
}

public class ConnectionPool {

    private DataSource ds;
    private static ConnectionPool mySelf;
    private ConnectionPool(DataSource ds) {
        this.ds = ds;
    }

    public static void init(DataSource ds) {
        mySelf = new ConnectionPool(ds);
    }

    public static ConnectionPool getInstance() {
        if (mySelf == null) {
            throw new IllegalStateException("Pool not initialized.");
        }
        return mySelf;
}
public Connection getConnection() throws SQLException {
    return ds.getConnection();
}
}


Any help would be greatly appreciated!
Thanks,
Mike






Similar Threads
Thread Thread Starter Forum Replies Last Post
Is anybody have sample app on Zend Framewok snowbydave1 Pro PHP 0 November 18th, 2008 10:52 AM
A question on bookstore sample app and pointbase partho_choudhury JSP Basics 0 April 9th, 2004 02:10 AM
A question on bookstore sample app and pointbase partho_choudhury Pro JSP 0 April 9th, 2004 02:09 AM
A question on bookstore sample app and pointbase partho_choudhury Java Databases 0 April 9th, 2004 02:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.