[jboss-user] [JNDI and Naming] - Error using JNDI datasouce on JBoss 7 for MySQL
Pirzada Rashid
do-not-reply at jboss.com
Mon Jul 9 12:36:24 EDT 2012
Pirzada Rashid [https://community.jboss.org/people/prashid] created the discussion
"Error using JNDI datasouce on JBoss 7 for MySQL"
To view the discussion, visit: https://community.jboss.org/message/746991#746991
--------------------------------------------------------------
I have spent many hrs try to fix the problem but no success. Googled and raed many related articles. followed this https://community.jboss.org/docs/DOC-16657 https://community.jboss.org/wiki/DataSourceConfigurationInAS7 also.
I want to connect MySQL database using JNDI dataSource on JBoss to reterive some data.
Someone please help.
*Error is generated as soon as I run test.jsp:*
javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for java:/jdbc/bookstore"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.test_jsp._jspService(test_jsp.java:90)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
+*This is what I got*+
MySQL Server 5.5:
database -> bookstore
table -> book
connector -> mysql-connector-java-5.1.21-bin.jar
container -> jboss-as-7.1.1.Final
IDE -> Eclipse juno
h3. STEP 1 - JBoss:
[JBoss_Home]/modules/com/mysql/main -> Got files below
module.xml
mysql-connector-java-5.1.21-bin.jar
mysql-connector-java-5.1.21-bin.jar -> this auto created
h5. module.xml contain:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.21-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
h3. STEP 2 JBoss:
[JBoss_Home]/standalone/configuration/standalone.xml
h5. standalone.xml added dataSource as below:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="true" jndi-name="java:/jdbc/bookstore" pool-name="bookstore_pool" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/bookstore</connection-url>
<driver>mysql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>root</user-name>
<password>786</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
h3. STEP 3 - Eclipse Project:
h5. test.jsp page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri=" http://java.sun.com/jsp/jstl/sql http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri=" http://java.sun.com/jsp/jstl/core http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="java:/jdbc/bookstore">
select title,description from book
</sql:query>
<html>
<head>
<title>DB Test</title>
</head>
<body>
<h2>Results</h2>
<c:forEach var="row" items="${rs.rows}">
Foo ${row.title}<br/>
Bar ${row.description}<br/>
</c:forEach>
</body>
</html>
h5. Add in web.xml:
<!-- JDBC DataSources (java:comp/env/jdbc) -->
<resource-ref>
<description>The used datasource</description>
<res-ref-name>jdbc/bookstore</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
h5. jboss-web.xml contains:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/bookstore</res-ref-name>
<jndi-name>java:/jdbc/bookstore</jndi-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</jboss-web>
+*Below is the project structure:*+
https://community.jboss.org/servlet/JiveServlet/showImage/2-746991-18963/pro.gif https://community.jboss.org/servlet/JiveServlet/downloadImage/2-746991-18963/303-600/pro.gif
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/746991#746991]
Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120709/81bc0536/attachment-0001.html
More information about the jboss-user
mailing list