  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | JDBC Driver, Context & DataSource lookup | JDBC Driver, Context & DataSource lookup 2005-08-16 - By Zumba
Back 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 (See http://ISO-8859.ora-code.com)-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, send email to listserv@(protected) and include in the body of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
|
|
 |