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



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to