Sorry guy, but read the original post again. ResourceLink is only required when the data source is defined as a global resource in server.xml. The poster defined the data source in the Context, not as a GlobalResource.

The real problem here: "Host 'localhost.localdomain' is not allowed to connect to this MySQL server". MySQL can deny users based on host as well as username and password. Make sure you can log into your MySQL server from the same machine running tomcat using the same credentials. I believe the mysql client command will try unix sockets by default first which doesn't really reproduce what tomcat will do. Try connecting with this from the command line:

mysql -u root -h localhost -P 3306  -p

The net effect here is to force the mysql client to connect using TCP/IP on port 3306 of the localhost. Also, and this is purely just a comment on your ResourceParams section. You might want to put the following in to use the DBCP pooling:

<parameter>
 <name>factory</name>
 <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

Hope this helps.

--David

Michael Eastwood wrote:


Hi Eric,

You also need a ResourceLink element in your Context. If you
rely on tomcat to create your contexts dynamically, AFAIK you'll
never pick up your datasource. So put a file named whatever
context you want your stuff under in $CATALINA_HOME/conf/Catalina/localhost/
if you're using the standard locations, and put something like this
in it:


<Context
    cookies="false"
    crossContext="false"
    docBase="news"
    path="/news"
    reloadable="true"
    debug="0">

    <ResourceLink
        global="Intranet"
        name="jdbc/intranet"
        type="javax.sql.DataSource">
    </ResourceLink>

</Context>

This is a 'news' context that references a datasource called 'intranet', defined in the server.xml file.

Good luck,

Michael

On 01/10/2004, at 4:09 PM, Eric Wulff wrote:

Hi, I am not able to access a mysql server from a simple jsp example.
I have googled the errors, checked mysql and tomcat docs and mailing
list archives without success.  Finding a tremendous amount of info
but nothing so far worked to solve my problem.  I created a data
resource in my server.xml.  I have defined a resource reference in my
web.xml.  I have tried shutting down my firewall.  I'm sure others
have had similar problems and I'm hoping one of you can share your
wisdom or point me in the right direction?

many thx
Eric

More, hopefully enlightening, details below.

fedoa core 2
tomcat 5
j2sdk 1.4.2
mysql 3.23.58 for linux redhat

-when mysql server is started I access it by simply typing 'mysql' at
the command line

following is web.xml, JNDI db res entry from the server.xml, and 3
error listings

-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>
    <servlet>
        <servlet-name>Database Rates</servlet-name>
        <servlet-class>DatabaseRates</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>DataSource Rates</servlet-name>
        <servlet-class>DataSourceRates</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>Rates</servlet-name>
        <jsp-file>/rates.jsp</jsp-file>
    </servlet>

    <servlet-mapping>
        <servlet-name>Database Rates</servlet-name>
        <url-pattern>/database</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>DataSource Rates</servlet-name>
        <url-pattern>/datasource</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Rates</servlet-name>
        <url-pattern>/rates</url-pattern>
    </servlet-mapping>

        <resource-ref>
          <res-ref-name>jdbc/conversion</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
        </resource-ref>
</web-app>

-server.xml JNDI db resource entry...
I have set a password for root to match the example but that didn't work.


<Context path="/database" docBase="database" debug="0" reloadable="true">
<ResourceParams name="jdbc/conversion">
<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value>secret</value>
</parameter>
<parameter>
<name>driverClassName</name>
<!-- <value>org.gjt.mm.mysql.Driver</value> tried both -->
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/test</value>
</parameter>
</ResourceParams>
</Context>


java.sql.SQLException: Data source rejected establishment of
connection, message from server: "Host 'localhost.localdomain' is not
allowed to connect to this MySQL server" SQL state: 08004
Error code: 1130

3 similar errors based on different db access strategies...
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver
of class '' for connect URL 'null' SQL state: null
Error code: 0

-error when using a datasource object...
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver
of class '' for connect URL 'null'

-stack trace when using a DAO via a .jsp...
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSourc e.java:780)
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.j ava:540)
converters.ConversionDAO.<init>(ConversionDAO.java:23)
org.apache.jsp.rates_jsp._jspService(rates_jsp.java:46)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.j ava:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: 292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



-I can create the test db table manually but can't via the java
program provided in the tutorial. This is the error I get when
attempting to run that...
java -classpath
.:/usr/local/jakarta-tomcat-5.0.28/common/lib/mysql-connector-java -3.0.15-ga-bin.jar
CreateDB
Loaded driver: com.mysql.jdbc.Driver
SQL Exception thrown: java.sql.SQLException: Data source rejected
establishment of connection, message from server: "Host
'localhost.localdomain' is not allowed to connect to this MySQL
server"
java.sql.SQLException: Data source rejected establishment of
connection, message from server: "Host 'localhost.localdomain' is not
allowed to connect to this MySQL server"
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:649)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1782)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java: 411)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at CreateDB.main(CreateDB.java:17)


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to