Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JDBC with MySQL 3.23.47 and Tomcat 4.1.18 (DBCP borrowObject failed: java.sql.SQLException: Server configuration denies access to data source)

Reply
Thread Tools

JDBC with MySQL 3.23.47 and Tomcat 4.1.18 (DBCP borrowObject failed: java.sql.SQLException: Server configuration denies access to data source)

 
 
ck388
Guest
Posts: n/a
 
      06-06-2003
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.BasicDataSourceFact ory</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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista denies permission to access folders: HELP! J Marshall NZ Computing 9 06-01-2007 02:31 AM
Tomcat 5.5 JDBC datasource config problem (MySQL) elektrophyte Java 3 01-30-2005 07:41 AM
REunning IIS on own Computer work - StandAloneServer denies access Greg Cyrus ASP .Net 0 01-10-2005 12:26 AM
OE denies access to attachments Cathie Guthrie Computer Support 3 05-12-2004 02:02 PM
Folder denies access... Murgi Computer Support 0 02-17-2004 08:00 AM



Advertisments