Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   JDBC with MySQL 3.23.47 and Tomcat 4.1.18 (DBCP borrowObject failed: java.sql.SQLException: Server configuration denies access to data source) (http://www.velocityreviews.com/forums/t123949-jdbc-with-mysql-3-23-47-and-tomcat-4-1-18-dbcp-borrowobject-failed-java-sql-sqlexception-server-configuration-denies-access-to-data-source.html)

ck388 06-06-2003 01:38 AM

JDBC with MySQL 3.23.47 and Tomcat 4.1.18 (DBCP borrowObject failed: java.sql.SQLException: Server configuration denies access to data source)
 
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 :-)


All times are GMT. The time now is 08:59 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.