JDBC with MySQL 3.23.47 and Tomcat 4.1.18 (DBCP borrowObject failed: java.sql.SQLException: Server c

Discussion in 'Java' started by ck388, Jun 6, 2003.

  1. ck388

    ck388 Guest

    When trying to display a test.jsp page i get this error message in
    Tomcat:

    DBCP borrowObject failed: java.sql.SQLException: Server configuration
    denies access to data source org.apache.commons.dbcp.DbcpException:
    java.sql.SQLException: Server configuration denies access to data
    source

    I will post my server.xml context section, web.xml, test.jsp, and
    DBTest.java files:

    ***********************************
    server.xml
    ***********************************

    <Context path="/MySqlDataSource" docBase="MySqlDataSource"
    debug="5" reloadable="true" crossContext="true">

    <Logger className="org.apache.catalina.logger.FileLogger"
    prefix="localhost_MySqlTest_log." suffix=".txt"
    timestamp="true"/>

    <Resource name="jdbc/mySqlTestDB"
    auth="Container"
    type="javax.sql.DataSource"/>

    <ResourceParams name="jdbc/mySqlTestDB">
    <parameter>
    <name>factory</name>
    <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>

    <!-- Maximum number of dB connections in pool. Make sure you
    configure your mysqld max_connections large enough to handle
    all of your db connections. Set to 0 for no limit.
    -->
    <parameter>
    <name>maxActive</name>
    <value>10</value>
    </parameter>

    <!-- Maximum number of idle dB connections to retain in pool.
    Set to 0 for no limit.
    -->
    <parameter>
    <name>maxIdle</name>
    <value>4</value>
    </parameter>

    <!-- Maximum time to wait for a dB connection to become available
    in ms, in this example 10 seconds. An Exception is thrown if
    this timeout is exceeded. Set to -1 to wait indefinitely.
    -->
    <parameter>
    <name>maxWait</name>
    <value>10000</value>
    </parameter>

    <!-- MySql dB username and password for dB connections -->
    <parameter>
    <name>username</name>
    <value>root</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>mysql</value>
    </parameter>

    <!-- Class name for MySql JDBC driver -->
    <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.Driver</value>
    </parameter>

    <!-- The JDBC connection url for connecting to your MySql dB.
    The autoReconnect=true argument to the url makes sure that the
    MySql JDBC Driver will automatically reconnect if MySql closed
    the
    connection.
    -->
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://192.168.1.254:3306/test</value>
    </parameter>
    </ResourceParams>
    </Context>

    ***********************************
    web.xml
    ***********************************

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <description>SqlServer Test App</description>
    <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/mySqlTestDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </web-app>

    ***********************************
    test.jsp
    ***********************************

    <html>
    <head>
    <title>DB Test</title>
    </head>
    <body>

    <%
    foo.DBTest tst = new foo.DBTest();
    tst.init();
    %>

    <h2>Results</h2>
    Foo <%= tst.getFoo() %><br/>
    Bar <%= tst.getBar() %>

    </body>
    </html>

    ***********************************
    DBTest.java
    ***********************************

    package foo;

    import javax.naming.*;
    import javax.sql.*;
    import java.sql.*;

    public class DBTest {

    String foo = "Not Connected";
    int bar = -1;

    public void init() {
    try{
    Context ctx = new InitialContext();
    if(ctx == null )
    throw new Exception("Boom - No Context");

    DataSource ds =
    (DataSource)ctx.lookup(
    "java:comp/env/jdbc/mySqlTestDB");

    if (ds != null) {
    Connection conn = ds.getConnection();

    if(conn != null) {
    foo = "Got Connection "+conn.toString();
    Statement stmt = conn.createStatement();
    ResultSet rst =
    stmt.executeQuery(
    "select foo, bar from testdata");
    if(rst.next()) {
    foo=rst.getString("foo");
    bar=rst.getInt("bar");
    }
    conn.close();
    }
    }
    }catch(Exception e) {
    e.printStackTrace();
    }
    }

    public String getFoo() { return foo; }
    public int getBar() { return bar;}
    }


    ********************************************

    Any ideas on how i can fix this problem?

    Thanks in advance,

    Tim :)
     
    ck388, Jun 6, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Scovetta
    Replies:
    0
    Views:
    3,123
    Michael Scovetta
    Jun 4, 2003
  2. Kermit Piper
    Replies:
    0
    Views:
    751
    Kermit Piper
    Jun 11, 2006
  3. Kermit Piper
    Replies:
    1
    Views:
    616
    Chris Uppal
    Jun 13, 2006
  4. mahesh
    Replies:
    3
    Views:
    4,783
    cb_1987
    Apr 6, 2010
  5. Lew
    Replies:
    0
    Views:
    481
Loading...

Share This Page