Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Aug 2005 16:21:08 -0300
From:      Zumba <freezumba@terra.com.br>
To:        freebsd-questions@freebsd.org
Subject:   JDBC Driver & lookup Context
Message-ID:  <1124133668.89496.28.camel@paulo.com>

next in thread | raw e-mail | index | archive | help
I'm trying to connect to mysql database using InitialContext and
DataSource lookup but it not works on FreeBSD 5.4 + tomcat 5.5 + jdk
1.5.0 + mysql-connector-java.jar (3.1.0) installed from ports. The
application seems that reads ok the JNDI Resources variables but when I
invoke dataSource.getConnection() I get the message on SQLException:
"Cannot create JDBC class for 'com.mysql.jdbc.Driver'. The fact is if I
use DriverManager.getConnection("jdbc:mysql//localhost/mysql?params")
without handle mysql-connector-java.jar and your directories it
(com.mysql.jdbc.Driver) works fine.

---- META-INF/context.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Context
docBase="${catalina.home}/webapps/Grid"
path="/Grid"
reloadable="true">
   <Resource
    name="jdbc/GridDB"
    type="javax.sql.DataSource"
    auth="Container"
    username="grid"
    password="abc123456"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost/griddb?autoReconnect=true"/>
</Context>

---- the reference on WEB-INF/Web.xml:
<resource-ref>
                <res-ref-name>jdbc/GridDB</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
</resource-ref>

---- servlet code:
Context initialContext = new InitialContext();
Context env = (Context) initialContext.lookup("java:comp/env");
DataSource dataSource = (DataSource) env.lookup("jdbc/GridDB");
connection = dataSource.getConnection();

Thanks,
Zumba







Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1124133668.89496.28.camel>