JNDI Data Source
manofspider Sep 3, 2008 12:22 AMI. I use:
- Oracle 10g
- j2sdk1.4.2_08
- jboss-4.0.2
- classes12.jar
II. data source file:
\jboss-4.0.2\server\simplej2ee\deploy\oracle-ds.xml:
<?xml version="1.0" encoding="UTF-8"?> <datasources> <local-tx-datasource> <jndi-name>training-db-ds</jndi-name> <connection-url>jdbc:oracle:thin:@srv06:1521:training</connection-url> <user-name>dbtest</user-name> <password>dbtest</password> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <min-pool-size>5</min-pool-size> <max-pool-size>20</max-pool-size> <idle-timeout-minutes>0</idle-timeout-minutes> </local-tx-datasource> </datasources>
III. example.jsp:
<%@page import="java.sql.Connection"%> <%@page import="java.sql.ResultSet"%> <%@page import="java.sql.SQLException"%> <%@page import="java.sql.Statement"%> <%@page import="javax.sql.DataSource"%> <%@page import="javax.naming.InitialContext"%> <HTML> <HEAD> <TITLE>Display Items</TITLE> </HEAD> <BODY> <h2>list of items:</h2> <% Connection con = null; InitialContext ic = null; String jndiname = null; DataSource ds = null; Statement stmt = null; ResultSet rs = null; try { ic = new InitialContext(); jndiname = "training-db-ds"; ds = (DataSource) ic.lookup("java:" + jndiname); con = ds.getConnection(); System.out.println("Connected to DB successfully."); stmt = con.createStatement(); rs = stmt.executeQuery("select * from tblitem"); while(rs.next()) { System.out.println("ITEM: " + rs.getString("id") + " " + rs.getString("name")); } } catch (SQLException e){ e.printStackTrace(); } finally { if(rs != null) rs.close(); if(stmt != null) stmt.close(); if(con != null) con.close(); } %> </BODY> </HTML>
IV. Output :
10:50:43,819 INFO [Server] Starting JBoss (MX MicroKernel)... 10:50:43,819 INFO [Server] Release ID: JBoss [Zion] 4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023) 10:50:43,819 INFO [Server] Home Dir: D:\Work\Install\jboss-4.0.2 10:50:43,819 INFO [Server] Home URL: file:/D:/Work/Install/jboss-4.0.2/ 10:50:43,819 INFO [Server] Library URL: file:/D:/Work/Install/jboss-4.0.2/lib/ 10:50:43,819 INFO [Server] Patch URL: null 10:50:43,819 INFO [Server] Server Name: simplej2ee 10:50:43,819 INFO [Server] Server Home Dir: D:\Work\Install\jboss-4.0.2\server\simplej2ee 10:50:43,819 INFO [Server] Server Home URL: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/ 10:50:43,819 INFO [Server] Server Data Dir: D:\Work\Install\jboss-4.0.2\server\simplej2ee\data 10:50:43,819 INFO [Server] Server Temp Dir: D:\Work\Install\jboss-4.0.2\server\simplej2ee\tmp 10:50:43,819 INFO [Server] Server Config URL: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/conf/ 10:50:43,819 INFO [Server] Server Library URL: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/lib/ 10:50:43,819 INFO [Server] Root Deployment Filename: jboss-service.xml 10:50:43,819 INFO [Server] Starting General Purpose Architecture (GPA)... 10:50:44,335 INFO [ServerInfo] Java version: 1.4.2_08,Sun Microsystems Inc. 10:50:44,335 INFO [ServerInfo] Java VM: Java HotSpot(TM) Client VM 1.4.2_08-b03,Sun Microsystems Inc. 10:50:44,335 INFO [ServerInfo] OS-System: Windows XP 5.1,x86 10:50:44,945 INFO [Server] Core system initialized 10:50:46,839 INFO [Log4jService$URLWatchTimerTask] Configuring from URL: resource:log4j.xml 10:50:47,011 INFO [WebService] Using RMI server codebase: http://tra10:8083/ 10:50:47,214 INFO [NamingService] Started jndi bootstrap jnpPort=1099, rmiPort=1098, backlog=50, bindAddress=/0.0.0.0, Client SocketFactory=null, Server SocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076 10:50:52,972 INFO [Embedded] Catalina naming disabled 10:50:53,582 INFO [Http11Protocol] Initializing Coyote HTTP/1.1 on http-0.0.0.0-8080 10:50:53,598 INFO [Catalina] Initialization processed in 532 ms 10:50:53,598 INFO [StandardService] Starting service jboss.web 10:50:53,613 INFO [StandardEngine] Starting Servlet Engine: Apache Tomcat/5.5.9 10:50:53,660 INFO [StandardHost] XML validation disabled 10:50:53,707 INFO [Catalina] Server startup in 109 ms 10:50:53,895 INFO [TomcatDeployer] deploy, ctxPath=/invoker, warUrl=file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/http-invoker.sar/invoker.war/ 10:50:54,364 INFO [WebappLoader] Dual registration of jndi stream handler: factory already defined 10:50:55,162 INFO [TomcatDeployer] deploy, ctxPath=/ws4ee, warUrl=file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/tmp/deploy/tmp5367jboss-ws4ee-exp.war/ 10:50:55,507 INFO [TomcatDeployer] deploy, ctxPath=/, warUrl=file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/jbossweb-tomcat55.sar/ROOT.war/ 10:50:55,835 INFO [TomcatDeployer] deploy, ctxPath=/jbossmq-httpil, warUrl=file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/jms/jbossmq-httpil.sar/jbossmq-httpil.war/ 10:50:58,667 INFO [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/management/console-mgr.sar/web-console.war/ 10:51:01,390 INFO [MailService] Mail Service bound to java:/Mail 10:51:02,250 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/jboss-ha-local-jdbc.rar 10:51:02,422 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/jboss-ha-xa-jdbc.rar 10:51:02,579 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/jboss-local-jdbc.rar 10:51:02,751 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/jboss-xa-jdbc.rar 10:51:02,892 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/jms/jms-ra.rar 10:51:03,032 INFO [RARDeployment] Required license terms exist view the META-INF/ra.xml: file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/mail-ra.rar 10:51:04,644 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=DefaultDS,service=DataSourceBinding to JNDI name 'java:DefaultDS' 10:51:05,066 INFO [A] Bound to JNDI name: queue/A 10:51:05,066 INFO Bound to JNDI name: queue/B 10:51:05,066 INFO [C] Bound to JNDI name: queue/C 10:51:05,082 INFO [D] Bound to JNDI name: queue/D 10:51:05,082 INFO [ex] Bound to JNDI name: queue/ex 10:51:05,113 INFO [testTopic] Bound to JNDI name: topic/testTopic 10:51:05,129 INFO [securedTopic] Bound to JNDI name: topic/securedTopic 10:51:05,129 INFO [testDurableTopic] Bound to JNDI name: topic/testDurableTopic 10:51:05,129 INFO [testQueue] Bound to JNDI name: queue/testQueue 10:51:05,207 INFO [UILServerILService] JBossMQ UIL service available at : /0.0.0.0:8093 10:51:05,285 INFO [DLQ] Bound to JNDI name: queue/DLQ 10:51:05,630 INFO [ConnectionFactoryBindingService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=JmsXA,service=ConnectionFactoryBinding to JNDI name 'java:JmsXA' 10:51:05,817 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=training-db-ds,service=DataSourceBinding to JNDI name 'java:training-db-ds' 10:51:05,880 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=file:/D:/Work/Install/jboss-4.0.2/server/simplej2ee/deploy/jmx-console.war/ 10:51:06,177 INFO [TomcatDeployer] deploy, ctxPath=/simplej2ee, warUrl=file:/D:/Work/eclipse/simplej2ee/training1/dist/appdev/simplej2ee.war/ 10:51:06,584 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080 10:51:06,756 INFO [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009 10:51:06,772 INFO [JkMain] Jk running ID=0 time=0/63 config=null 10:51:06,787 INFO [Server] JBoss (MX MicroKernel) [4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)] Started in 22s:968ms 10:51:27,034 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: oracle.jdbc.driver.OracleDriver, url: jdbc:oracle:thin:@srv06:1521:training) at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:161) at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:508) at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:207) at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:534) at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:395) at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:297) at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:447) at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:874) at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:103) at org.apache.jsp._1_005fJspDb.example_jsp._jspService(org.apache.jsp._1_005fJspDb.example_jsp:76) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) at javax.servlet.http.HttpServlet.service(HttpServlet.java:810) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) at javax.servlet.http.HttpServlet.service(HttpServlet.java:810) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112) at java.lang.Thread.run(Thread.java:534) Caused by: org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: oracle.jdbc.driver.OracleDriver, url: jdbc:oracle:thin:@srv06:1521:training at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:288) at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:150) ... 34 more 10:51:27,034 INFO [STDOUT] org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: oracle.jdbc.driver.OracleDriver, url: jdbc:oracle:thin:@srv06:1521:training); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: oracle.jdbc.driver.OracleDriver, url: jdbc:oracle:thin:@srv06:1521:training)) 10:51:27,034 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:107) 10:51:27,034 INFO [STDOUT] at org.apache.jsp._1_005fJspDb.example_jsp._jspService(org.apache.jsp._1_005fJspDb.example_jsp:76) 10:51:27,034 INFO [STDOUT] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) 10:51:27,034 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810) 10:51:27,034 INFO [STDOUT] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) 10:51:27,034 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) 10:51:27,034 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) 10:51:27,034 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810) 10:51:27,034 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) 10:51:27,034 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) 10:51:27,034 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81) 10:51:27,049 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) 10:51:27,049 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) 10:51:27,049 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 10:51:27,049 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) 10:51:27,049 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39) 10:51:27,049 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153) 10:51:27,049 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59) 10:51:27,049 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) 10:51:27,049 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) 10:51:27,049 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) 10:51:27,049 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) 10:51:27,049 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) 10:51:27,049 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744) 10:51:27,049 INFO [STDOUT] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) 10:51:27,049 INFO [STDOUT] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112) 10:51:27,049 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534) 10:51:27,049 INFO [STDOUT] Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: oracle.jdbc.driver.OracleDriver, url: jdbc:oracle:thin:@srv06:1521:training) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:161) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:508) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:207) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:534) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:395) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:297) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:447) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:874) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:103) 10:51:27,049 INFO [STDOUT] ... 26 more 10:51:27,049 INFO [STDOUT] Caused by: org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: oracle.jdbc.driver.OracleDriver, url: jdbc:oracle:thin:@srv06:1521:training 10:51:27,049 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:288) 10:51:27,049 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:150) 10:51:27,049 INFO [STDOUT] ... 34 more 10:51:36,359 INFO [STDOUT] Connected to DB successfully. 10:51:36,578 INFO [STDOUT] ITEM: 1 Monitor 10:51:36,578 INFO [STDOUT] ITEM: 2 Keyboard 10:51:36,578 INFO [STDOUT] ITEM: 3 Mouse 10:51:41,585 INFO [STDOUT] Connected to DB successfully. 10:51:41,585 INFO [STDOUT] ITEM: 1 Monitor 10:51:41,585 INFO [STDOUT] ITEM: 2 Keyboard 10:51:41,585 INFO [STDOUT] ITEM: 3 Mouse 10:51:42,868 INFO [STDOUT] Connected to DB successfully. 10:51:42,883 INFO [STDOUT] ITEM: 1 Monitor 10:51:42,883 INFO [STDOUT] ITEM: 2 Keyboard 10:51:42,883 INFO [STDOUT] ITEM: 3 Mouse
V. Questioin:
Why the first time that example.jsp is load with error of connection ? But when reload current page many times later, it works fine as u see in the log.
Plz could you explain to me, what is exactly wrong? It missed something?
Thank in advance.