rr87
asked on
JBoss connection pooling for PL/SQL - Struts 2 with manual jdbc crud operations
Hi,
Im a pretty new java programmer. Im actually trying to develop a web application with JBoss. The tech stack is Struts 2 with jsp+jquery for UI. I was asked to do manual JDBC connection to my Oracle 11g pl/sql database.
Can some one explain me how to configure jdbc connection and also the connection pool in jboss manually(without using the admin console) and also access the database using the JNDI look up for crud operations?? Also correct me if im wrong but i will also need to implement session management?? how is this helpful & how can this be done?? what is the best method.
I would really appreciate detailed explanation and sample code.
Thanks in advance!!
Im a pretty new java programmer. Im actually trying to develop a web application with JBoss. The tech stack is Struts 2 with jsp+jquery for UI. I was asked to do manual JDBC connection to my Oracle 11g pl/sql database.
Can some one explain me how to configure jdbc connection and also the connection pool in jboss manually(without using the admin console) and also access the database using the JNDI look up for crud operations?? Also correct me if im wrong but i will also need to implement session management?? how is this helpful & how can this be done?? what is the best method.
I would really appreciate detailed explanation and sample code.
Thanks in advance!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also https://community.jboss.org/message/251298#251298 could be useful
ASKER
Im confused.... according to https://community.jboss.org/wiki/HowDoICreateAResourceRef i will also need to modify web.xml and jboss-web.xml..... Why is this necessary?? if it is not than when would i need to configure them????
it is according to J2EE specifications. You should provide links to the resources in the web.xml
ASKER
So basically i have to once i do the *-ds.xml file and add the driver to my jboss, i also have to create web.xml file??? I use struts 2 framework and my application already has a web.xml file... is this the same file you mentioned here....if so so i just add the following inside that file??
What about this file below...Where is this located ?? do i create one or do i just append to an existing file?
The *-ds.xml file has the JNDI name as peopleDS . so how will the above 2 codes change??
web.xml excerpt:
<resource-ref>
<res-ref-name>jdbc/TheDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
What about this file below...Where is this located ?? do i create one or do i just append to an existing file?
jboss-web.xml:
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/TheDS</res-ref-name>
<jndi-name>java:jdbc/SomeDS</jndi-name>
</resource-ref>
</jboss-web>
The *-ds.xml file has the JNDI name as peopleDS . so how will the above 2 codes change??
1. you should use existing web.xml to and add:
<resource-ref>
<res-ref-name>jdbc/TheDS</ res-ref-na me>
<res-type>javax.sql.DataSo urce</res- type>
<res-auth>Container</res-a uth>
<res-sharing-scope>Shareab le</res-sh aring-scop e>
</resource-ref>
2. in jboss-web.xml which is located in the same directory where web.xml is (WEB-INF) you add:
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/TheDS</ res-ref-na me>
<jndi-name>java:/peopleDS< /jndi-name >
</resource-ref>
</jboss-web>
after that you can use in your servlets and jsp pages:
InitialContext ctx= new InitialContext();
Datasource ds = (DataSource)ctx.lookup("jd bc/theDS")
<resource-ref>
<res-ref-name>jdbc/TheDS</
<res-type>javax.sql.DataSo
<res-auth>Container</res-a
<res-sharing-scope>Shareab
</resource-ref>
2. in jboss-web.xml which is located in the same directory where web.xml is (WEB-INF) you add:
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/TheDS</
<jndi-name>java:/peopleDS<
</resource-ref>
</jboss-web>
after that you can use in your servlets and jsp pages:
InitialContext ctx= new InitialContext();
Datasource ds = (DataSource)ctx.lookup("jd
ASKER
I do not have a jboss-web.xml file in my project... My application runs fine in jboss except that im still trying to setup the database part of it. Do i need to create this file???
ASKER
so i added the *-ds.xml file and also the resource ref in my web.xml.... I tried to run the application and one of the errors im getting is
org.jboss.deployment.Deplo ymentExcep tion: Error during deploy; - nested throwable: (javax.naming.NamingExcept ion: resource-ref: jdbc/TheDS has no valid JNDI binding. Check the jboss-web/resource-ref
So im guessing the jboss-web.xml file is definitelyt needed but i dont have this file in my application....should i create one ?? where to place it ?? and what all will this file contain??
org.jboss.deployment.Deplo
So im guessing the jboss-web.xml file is definitelyt needed but i dont have this file in my application....should i create one ?? where to place it ?? and what all will this file contain??
ASKER
So i created a jboss-web.xml file under the WEB-INF folder in my application as below
And i access it like
When i run the application i get the following error
15:41:38,603 INFO [ConnectionFactoryBindingS ervice] Bound ConnectionManager 'jboss.jca:service=DataSou rceBinding ,name=peop leDS' to JNDI name 'java:peopleDS'
15:41:38,653 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-cons ole.war/
15:41:38,866 WARN [NestedThrowable] Duplicate throwable nesting of same base type: class org.jboss.deployment.Deplo ymentExcep tion is assignable from: class org.jboss.deployment.Deplo ymentExcep tion
15:41:38,867 ERROR [MainDeployer] Could not initialise deployment: file:/C:/Program Files/jboss-as/server/defa ult/deploy /people.wa r
org.jboss.deployment.Deplo ymentExcep tion: Failed to parse WEB-INF/jboss-web.xml; - nested throwable: (org.jboss.deployment.Depl oymentExce ption: Invalid XML: file=file:/C:/Program Files/jboss-as/server/defa ult/tmp/de ploy/tmp78 7941303621 9406005peo ple-exp.wa r//WEB-INF /jboss-web .xml@-1:-1 ; - nested throwable: (org.xml.sax.SAXParseExcep tion: Premature end of file.))
at org.jboss.web.AbstractWebC ontainer.p arseMetaDa ta(Abstrac tWebContai ner.java:7 68)
at org.jboss.web.AbstractWebC ontainer.i nit(Abstra ctWebConta iner.java: 356)
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
at org.jboss.mx.interceptor.R eflectedDi spatcher.i nvoke(Refl ectedDispa tcher.java :155)
at org.jboss.mx.server.Invoca tion.dispa tch(Invoca tion.java: 94)
at org.jboss.mx.interceptor.A bstractInt erceptor.i nvoke(Abst ractInterc eptor.java :133)
at org.jboss.mx.server.Invoca tion.invok e(Invocati on.java:88 )
at org.jboss.mx.interceptor.M odelMBeanO perationIn terceptor. invoke(Mod elMBeanOpe rationInte rceptor.ja va:142)
at org.jboss.mx.interceptor.D ynamicInte rceptor.in voke(Dynam icIntercep tor.java:9 7)
at org.jboss.system.Intercept orServiceM BeanSuppor t.invokeNe xt(Interce ptorServic eMBeanSupp ort.java:2 38)
at org.jboss.deployment.SubDe ployerInte rceptorSup port.init( SubDeploye rIntercept orSupport. java:119)
at org.jboss.deployment.SubDe ployerInte rceptorSup port$XMBea nIntercept or.init(Su bDeployerI nterceptor Support.ja va:172)
at org.jboss.deployment.SubDe ployerInte rceptor.in voke(SubDe ployerInte rceptor.ja va:87)
at org.jboss.mx.server.Invoca tion.invok e(Invocati on.java:88 )
at org.jboss.mx.server.Abstra ctMBeanInv oker.invok e(Abstract MBeanInvok er.java:26 4)
at org.jboss.mx.server.MBeanS erverImpl. invoke(MBe anServerIm pl.java:65 9)
at org.jboss.mx.util.MBeanPro xyExt.invo ke(MBeanPr oxyExt.jav a:210)
at $Proxy45.init(Unknown Source)
at org.jboss.deployment.MainD eployer.in it(MainDep loyer.java :872)
at org.jboss.deployment.MainD eployer.de ploy(MainD eployer.ja va:809)
at org.jboss.deployment.MainD eployer.de ploy(MainD eployer.ja va:782)
at sun.reflect.GeneratedMetho dAccessor2 5.invoke(U nknown Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
at org.jboss.mx.interceptor.R eflectedDi spatcher.i nvoke(Refl ectedDispa tcher.java :155)
at org.jboss.mx.server.Invoca tion.dispa tch(Invoca tion.java: 94)
at org.jboss.mx.interceptor.A bstractInt erceptor.i nvoke(Abst ractInterc eptor.java :133)
at org.jboss.mx.server.Invoca tion.invok e(Invocati on.java:88 )
at org.jboss.mx.interceptor.M odelMBeanO perationIn terceptor. invoke(Mod elMBeanOpe rationInte rceptor.ja va:142)
at org.jboss.mx.server.Invoca tion.invok e(Invocati on.java:88 )
at org.jboss.mx.server.Abstra ctMBeanInv oker.invok e(Abstract MBeanInvok er.java:26 4)
at org.jboss.mx.server.MBeanS erverImpl. invoke(MBe anServerIm pl.java:65 9)
at org.jboss.mx.util.MBeanPro xyExt.invo ke(MBeanPr oxyExt.jav a:210)
at $Proxy9.deploy(Unknown Source)
at org.jboss.deployment.scann er.URLDepl oymentScan ner.deploy (URLDeploy mentScanne r.java:421 )
at org.jboss.deployment.scann er.URLDepl oymentScan ner.scan(U RLDeployme ntScanner. java:634)
at org.jboss.deployment.scann er.Abstrac tDeploymen tScanner$S cannerThre ad.doScan( AbstractDe ploymentSc anner.java :263)
at org.jboss.deployment.scann er.Abstrac tDeploymen tScanner.s tartServic e(Abstract Deployment Scanner.ja va:336)
at org.jboss.system.ServiceMB eanSupport .jbossInte rnalStart( ServiceMBe anSupport. java:289)
at org.jboss.system.ServiceMB eanSupport .jbossInte rnalLifecy cle(Servic eMBeanSupp ort.java:2 45)
at sun.reflect.GeneratedMetho dAccessor3 .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
at org.jboss.mx.interceptor.R eflectedDi spatcher.i nvoke(Refl ectedDispa tcher.java :155)
at org.jboss.mx.server.Invoca tion.dispa tch(Invoca tion.java: 94)
at org.jboss.mx.server.Invoca tion.invok e(Invocati on.java:86 )
at org.jboss.mx.server.Abstra ctMBeanInv oker.invok e(Abstract MBeanInvok er.java:26 4)
at org.jboss.mx.server.MBeanS erverImpl. invoke(MBe anServerIm pl.java:65 9)
at org.jboss.system.ServiceCo ntroller$S erviceProx y.invoke(S erviceCont roller.jav a:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceCo ntroller.s tart(Servi ceControll er.java:41 7)
at sun.reflect.GeneratedMetho dAccessor9 .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
at org.jboss.mx.interceptor.R eflectedDi spatcher.i nvoke(Refl ectedDispa tcher.java :155)
at org.jboss.mx.server.Invoca tion.dispa tch(Invoca tion.java: 94)
at org.jboss.mx.server.Invoca tion.invok e(Invocati on.java:86 )
at org.jboss.mx.server.Abstra ctMBeanInv oker.invok e(Abstract MBeanInvok er.java:26 4)
at org.jboss.mx.server.MBeanS erverImpl. invoke(MBe anServerIm pl.java:65 9)
at org.jboss.mx.util.MBeanPro xyExt.invo ke(MBeanPr oxyExt.jav a:210)
at $Proxy4.start(Unknown Source)
at org.jboss.deployment.SARDe ployer.sta rt(SARDepl oyer.java: 302)
at org.jboss.deployment.MainD eployer.st art(MainDe ployer.jav a:1025)
at org.jboss.deployment.MainD eployer.de ploy(MainD eployer.ja va:819)
at org.jboss.deployment.MainD eployer.de ploy(MainD eployer.ja va:782)
at org.jboss.deployment.MainD eployer.de ploy(MainD eployer.ja va:766)
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
at org.jboss.mx.interceptor.R eflectedDi spatcher.i nvoke(Refl ectedDispa tcher.java :155)
at org.jboss.mx.server.Invoca tion.dispa tch(Invoca tion.java: 94)
at org.jboss.mx.interceptor.A bstractInt erceptor.i nvoke(Abst ractInterc eptor.java :133)
at org.jboss.mx.server.Invoca tion.invok e(Invocati on.java:88 )
at org.jboss.mx.interceptor.M odelMBeanO perationIn terceptor. invoke(Mod elMBeanOpe rationInte rceptor.ja va:142)
at org.jboss.mx.server.Invoca tion.invok e(Invocati on.java:88 )
at org.jboss.mx.server.Abstra ctMBeanInv oker.invok e(Abstract MBeanInvok er.java:26 4)
at org.jboss.mx.server.MBeanS erverImpl. invoke(MBe anServerIm pl.java:65 9)
at org.jboss.mx.util.MBeanPro xyExt.invo ke(MBeanPr oxyExt.jav a:210)
at $Proxy5.deploy(Unknown Source)
at org.jboss.system.server.Se rverImpl.d oStart(Ser verImpl.ja va:482)
at org.jboss.system.server.Se rverImpl.s tart(Serve rImpl.java :362)
at org.jboss.Main.boot(Main.j ava:200)
at org.jboss.Main$1.run(Main. java:508)
at java.lang.Thread.run(Unkno wn Source)
Caused by: org.jboss.deployment.Deplo ymentExcep tion: Invalid XML: file=file:/C:/Program Files/jboss-as/server/defa ult/tmp/de ploy/tmp78 7941303621 9406005peo ple-exp.wa r//WEB-INF /jboss-web .xml@-1:-1 ; - nested throwable: (org.xml.sax.SAXParseExcep tion: Premature end of file.)
at org.jboss.metadata.XmlFile Loader.get Document(X mlFileLoad er.java:34 2)
at org.jboss.metadata.XmlFile Loader.get Document(X mlFileLoad er.java:27 2)
at org.jboss.web.AbstractWebC ontainer.p arseMetaDa ta(Abstrac tWebContai ner.java:7 61)
... 87 more
Caused by: org.xml.sax.SAXParseExcept ion: Premature end of file.
at org.apache.xerces.parsers. DOMParser. parse(Unkn own Source)
at org.apache.xerces.jaxp.Doc umentBuild erImpl.par se(Unknown Source)
at org.jboss.metadata.XmlFile Loader.get Document(X mlFileLoad er.java:32 8)
... 89 more
15:41:38,868 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
--- Incompletely deployed packages ---
org.jboss.deployment.Deplo ymentInfo@ 55a2b9e4 { url=file:/C:/Program Files/jboss-as/server/defa ult/deploy /people.wa r }
deployer: MBeanProxyExt[jboss.web:se rvice=WebS erver]
status: null
state: FAILED
watch: file:/C:/Program Files/jboss-as/server/defa ult/deploy /people.wa r
altDD: null
lastDeployed: 1346355698867
lastModified: 1346355698858
mbeans:
<!DOCTYPE jboss-web PUBLIC
"-//JBoss//DTD Web Application 2.4//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/peopleDS</res-ref-name>
<jndi-name>java:/peopleDS</jndi-name>
</resource-ref>
</jboss-web>
And i access it like
InitialContext icx = new InitialContext();
DataSource ds = (DataSource)icx.lookup("jdbc/peopleDS");
Connection conn = ds.getConnection();
When i run the application i get the following error
15:41:38,603 INFO [ConnectionFactoryBindingS
15:41:38,653 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-cons
15:41:38,866 WARN [NestedThrowable] Duplicate throwable nesting of same base type: class org.jboss.deployment.Deplo
15:41:38,867 ERROR [MainDeployer] Could not initialise deployment: file:/C:/Program Files/jboss-as/server/defa
org.jboss.deployment.Deplo
at org.jboss.web.AbstractWebC
at org.jboss.web.AbstractWebC
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at org.jboss.mx.interceptor.R
at org.jboss.mx.server.Invoca
at org.jboss.mx.interceptor.A
at org.jboss.mx.server.Invoca
at org.jboss.mx.interceptor.M
at org.jboss.mx.interceptor.D
at org.jboss.system.Intercept
at org.jboss.deployment.SubDe
at org.jboss.deployment.SubDe
at org.jboss.deployment.SubDe
at org.jboss.mx.server.Invoca
at org.jboss.mx.server.Abstra
at org.jboss.mx.server.MBeanS
at org.jboss.mx.util.MBeanPro
at $Proxy45.init(Unknown Source)
at org.jboss.deployment.MainD
at org.jboss.deployment.MainD
at org.jboss.deployment.MainD
at sun.reflect.GeneratedMetho
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at org.jboss.mx.interceptor.R
at org.jboss.mx.server.Invoca
at org.jboss.mx.interceptor.A
at org.jboss.mx.server.Invoca
at org.jboss.mx.interceptor.M
at org.jboss.mx.server.Invoca
at org.jboss.mx.server.Abstra
at org.jboss.mx.server.MBeanS
at org.jboss.mx.util.MBeanPro
at $Proxy9.deploy(Unknown Source)
at org.jboss.deployment.scann
at org.jboss.deployment.scann
at org.jboss.deployment.scann
at org.jboss.deployment.scann
at org.jboss.system.ServiceMB
at org.jboss.system.ServiceMB
at sun.reflect.GeneratedMetho
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at org.jboss.mx.interceptor.R
at org.jboss.mx.server.Invoca
at org.jboss.mx.server.Invoca
at org.jboss.mx.server.Abstra
at org.jboss.mx.server.MBeanS
at org.jboss.system.ServiceCo
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceCo
at sun.reflect.GeneratedMetho
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at org.jboss.mx.interceptor.R
at org.jboss.mx.server.Invoca
at org.jboss.mx.server.Invoca
at org.jboss.mx.server.Abstra
at org.jboss.mx.server.MBeanS
at org.jboss.mx.util.MBeanPro
at $Proxy4.start(Unknown Source)
at org.jboss.deployment.SARDe
at org.jboss.deployment.MainD
at org.jboss.deployment.MainD
at org.jboss.deployment.MainD
at org.jboss.deployment.MainD
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at org.jboss.mx.interceptor.R
at org.jboss.mx.server.Invoca
at org.jboss.mx.interceptor.A
at org.jboss.mx.server.Invoca
at org.jboss.mx.interceptor.M
at org.jboss.mx.server.Invoca
at org.jboss.mx.server.Abstra
at org.jboss.mx.server.MBeanS
at org.jboss.mx.util.MBeanPro
at $Proxy5.deploy(Unknown Source)
at org.jboss.system.server.Se
at org.jboss.system.server.Se
at org.jboss.Main.boot(Main.j
at org.jboss.Main$1.run(Main.
at java.lang.Thread.run(Unkno
Caused by: org.jboss.deployment.Deplo
at org.jboss.metadata.XmlFile
at org.jboss.metadata.XmlFile
at org.jboss.web.AbstractWebC
... 87 more
Caused by: org.xml.sax.SAXParseExcept
at org.apache.xerces.parsers.
at org.apache.xerces.jaxp.Doc
at org.jboss.metadata.XmlFile
... 89 more
15:41:38,868 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
--- Incompletely deployed packages ---
org.jboss.deployment.Deplo
deployer: MBeanProxyExt[jboss.web:se
status: null
state: FAILED
watch: file:/C:/Program Files/jboss-as/server/defa
altDD: null
lastDeployed: 1346355698867
lastModified: 1346355698858
mbeans:
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
my suggestion - if it work - do not touch ;)
But normally you should put jboss-web.xml file in the WEB-INF folder and define resource-red element there and map it also in the web.xml. But probably with latest jboss releases JBoss developers simplified the life of application developers, so you can directly access JNDI resources (like db datasource in your case) without that duplication of definitions.
But normally you should put jboss-web.xml file in the WEB-INF folder and define resource-red element there and map it also in the web.xml. But probably with latest jboss releases JBoss developers simplified the life of application developers, so you can directly access JNDI resources (like db datasource in your case) without that duplication of definitions.
ASKER
Thank you !
ASKER
closing the question
ASKER
The solution was achieved but with some confusion as to the configurations in web.xml and jboss-web.xml files. Which according to an article recommended was required but on further trial and error it was found to be not necessary.
ASKER