My mission is to connect Tomcat 7 to remote IBM MQ. I try create JNDI Resource in server.xml file but it doesn't work. I used example from.
Addinatinaly i added in this example username and password. But there is error when i call JNDI resource from java code.
<Resource
name="jms/MyQCF"
auth="Container"
type="com.ibm.mq.jms.MQQueueConnectionFactory"
factory="com.ibm.mq.jms.MQQueueConnectionFactoryFactory"
description="JMS Queue Connection Factory for sending messages"
HOST="<mymqserver>"
PORT="1414"
CHAN="<mychannel>"
TRAN="1"
QMGR="<myqueuemanager>"/>
<Resource
name="jms/MyQ"
auth="Container"
type="com.ibm.mq.jms.MQQueue"
factory="com.ibm.mq.jms.MQQueueFactory"
description="JMS Queue for receiving messages from Dialog"
QU="<myqueue>"/>
I've downloaded all required *.jars from [IBM sphere]/lib/java to Tomcat lib folder. Help me please, mb i'm doing somethink wrong. Maybe i need some IBM Client, but i don't know what is it.
Edit:
The error stacktrace
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:117)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
VERSION OF IBM MQ LIBS IS:
Implementation-Version: 7.0.1.8 - k701-108-120201
My current Resource in server.xml is:
<Resource
name="jms/MyQCF"
auth="Container"
type="org.springframework.jms.connection.CachingConnectionFactory"
factory="com.ibm.mq.jms.MQQueueConnectionFactoryFactory"
description="JMS Queue Connection Factory for sending messages"
HOST="192.168.204.73"
PORT="1415"
username="***"
password="***"
CHAN="JAVA.CHANNEL"
TRAN="1"
QMGR="U.SEND"/>
<Resource
name="jms/MyQ"
auth="Container"
type="com.ibm.mq.jms.MQQueue"
factory="com.ibm.mq.jms.MQQueueFactory"
description="JMS Queue for receiving messages from Dialog"
QU="U.RECEIVE"/>
My java code:
System.out.println("servlet page*****************");
Context ctx = null;
try {
ctx = (Context) new InitialContext().lookup("java:comp/env");
System.out.println("ctx: " + ctx);
} catch (NamingException e) {
e.printStackTrace();
}
QueueConnectionFactory qcf = null;
try {
qcf = (QueueConnectionFactory) ctx.lookup("jms/MyQCF");
System.out.println("qcf: " + qcf);
} catch (NamingException e) {
e.printStackTrace();
}
My stacktrace:
servlet page*****************
ctx: org.apache.naming.NamingContext#463b1a3e
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:117)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at kz.lalafa.MyServlet.doPost(MyServlet.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
My Tomcat lib folder contains:
annotations-api.jar
fscontext.jar
catalina-ant.jar
geronimo-j2ee-management_1.1_spec-1.0.1.jar
catalina-ha.jar
geronimo-jms_1.1_spec-1.1.1.jar
catalina.jar
jasper-el.jar
catalina-tribes.jar
jasper.jar
CL3Export.jar
jms.jar
CL3Nonexport.jar
jndi.jar
com.ibm.mq.commonservices.jar
jsp-api.jar
com.ibm.mq.defaultconfig.jar
jta.jar
com.ibm.mqetclient.jar
ldap.jar
com.ibm.mq.headers.jar
providerutil.jar
com.ibm.mq.jar
rmm.jar
com.ibm.mq.jmqi.jar
servlet-api.jar
com.ibm.mqjms.jar
tomcat-api.jar
com.ibm.mq.jms.Nojndi.jar
tomcat-coyote.jar
com.ibm.mq.pcf.jar
tomcat-dbcp.jar
com.ibm.mq.postcard.jar
tomcat-i18n-es.jar
com.ibm.mq.soap.jar
tomcat-i18n-fr.jar
com.ibm.mq.tools.ras.jar
tomcat-i18n-ja.jar
connector.jar
tomcat-jdbc.jar
dhbcore.jar
tomcat-util.jar
ecj-4.2.2.jar
wmq.jmsra.rar
el-api.jar
My web.xml:
<?xml version='1.0' encoding='utf-8'?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<resource-env-ref>
<resource-env-ref-name>jms/MyQCF</resource-env-ref-name>
<resource-env-ref-type>javax.jms.QueueConnectionFactory</resource-env-ref-type>
</resource-env-ref>
<resource-env-ref>
<resource-env-ref-name>jms/MyQ</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
</web-app>
I just decided to use Spring Boot for this - https://github.com/lzp4ever/IBM_WebSphere_MQ_Spring_Boot_JMS.
But i got new problem. My new problem at this link: multiple jms connection factory
Related
I am using JNDI datasource to connect to Postgres database. This is the code to of my ServletContextListener
public void contextInitialized(ServletContextEvent event) {
try {
// Obtain our environment naming context
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
// initialize JNDI lookup parameters
DataSource datasource = (DataSource) envCtx.lookup("jdbc/testdb");
ManagerDao.getConn(datasource);
ParticipantDao.getConn(datasource);
EventDao.getConn(datasource);
FacilitiesDao.getConn(datasource);
}
catch (NamingException e) {
e.printStackTrace();
}
}
web.xml of App_path\WebContent\WEB-INF
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/testdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
context.xml
<Resource name="jdbc/testdb"
auth="Container"
type="javax.sql.DataSource"
username="postgres"
password="rules#123"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5433/eventory"
maxActive="20" maxIdle="10"
/>
But I am getting errors while the getConnection() methods are getting called.
java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2167)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2037)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1543)
at com.eventory.dao.FacilitiesDao.getConn(FacilitiesDao.java:26)
at com.eventory.initDB.DBConnListener.contextInitialized(DBConnListener.java:48)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2151)
... 13 more
I have tried the following approaches:
Put the postgresql-42.1.4.jar in the tomcat lib folder.
Put the postgresql-42.1.4.jar in the App_Path\WebContent\WEB-INF\lib
Put the context.xml in the WebContent\META-INF folder
Put the context.xml in the tomcat\conf folder
Nothing seems to work. Is there any other approach that I missed? Please help.
Everything works fine in eclipse on my test machine, but when I deploy the WAR to the server I receive "Cannot locate JNDI Resource" errors on each attempt to connect with the database.
I am using a resource within WEB-INF/context.xml. The mysql-connector-java-5.1.25-bin.jar is located within the lib folder of the app. I've tried everything I can think of. I'm assuming its a tomcat specific problem because it works fine on the tomcat installation in eclipse. Is there a setting I am missing?
The context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/appointmentree" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
url="jdbc:mysql://1.1.1.1/appointmentree"
driverClassName="com.mysql.jdbc.Driver"
username="appointmentree" password="password"
/>
</Context>
The resulting error:
fm.sprout.java.db.DatabaseConnectionException: appointmentree is missing in JNDI.
fm.sprout.java.db.DBConnection.<init>(DBConnection.java:17)
fm.sprout.java.db.MySqlDBHandler.find(MySqlDBHandler.java:108)
com.appointmentree.db.DBUser.findAll(DBUser.java:173)
com.appointmentree.db.DBUser.find(DBUser.java:146)
com.appointmentree.db.DBUser.find(DBUser.java:142)
com.appointmentree.obj.User.getInstance(User.java:39)
com.appointmentree.seeds.Login$1.handle(Login.java:39)
fm.sprout.java.forms.FormHandler.init(FormHandler.java:53)
fm.sprout.java.views.SeedBuilder.post(SeedBuilder.java:103)
com.appointmentree.seeds.Login.onLoad(Login.java:33)
fm.sprout.java.views.SeedPlanter.sow(SeedPlanter.java:131)
fm.sprout.java.session.RequestHandler.doPost(RequestHandler.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
com.appointmentree.session.UserSessionFilter.doFilter(UserSessionFilter.java:72)
root cause
javax.naming.NamingException: com.mysql.jdbc.Driver
org.apache.naming.NamingContext.lookup(NamingContext.java:859)
org.apache.naming.NamingContext.lookup(NamingContext.java:153)
org.apache.naming.NamingContext.lookup(NamingContext.java:830)
org.apache.naming.NamingContext.lookup(NamingContext.java:153)
org.apache.naming.NamingContext.lookup(NamingContext.java:830)
org.apache.naming.NamingContext.lookup(NamingContext.java:153)
org.apache.naming.NamingContext.lookup(NamingContext.java:830)
org.apache.naming.NamingContext.lookup(NamingContext.java:167)
org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
javax.naming.InitialContext.lookup(InitialContext.java:411)
fm.sprout.java.db.DBConnection.<init>(DBConnection.java:15)
fm.sprout.java.db.MySqlDBHandler.find(MySqlDBHandler.java:108)
com.appointmentree.db.DBUser.findAll(DBUser.java:173)
com.appointmentree.db.DBUser.find(DBUser.java:146)
com.appointmentree.db.DBUser.find(DBUser.java:142)
com.appointmentree.obj.User.getInstance(User.java:39)
com.appointmentree.seeds.Login$1.handle(Login.java:39)
fm.sprout.java.forms.FormHandler.init(FormHandler.java:53)
fm.sprout.java.views.SeedBuilder.post(SeedBuilder.java:103)
com.appointmentree.seeds.Login.onLoad(Login.java:33)
fm.sprout.java.views.SeedPlanter.sow(SeedPlanter.java:131)
fm.sprout.java.session.RequestHandler.doPost(RequestHandler.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
com.appointmentree.session.UserSessionFilter.doFilter(UserSessionFilter.java:72)
The resource in web.xml
<resource-env-ref>
<resource-env-ref-name>jdbc/appointmentree</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
Try using this:
<resource-ref>
<res-ref-name>jdbc/appointmentree</res-ref-name>
<res-ref-type>javax.sql.DataSource</res-ref-type>
<res-auth>Container</res-auth>
</resource-ref>
I got this information from here: http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitions
Turns out I hadn't included the mysql connector jar in the CATALINA_HOME/lib folder. I was under the impression that having the connector in the lib folder of the application was sufficient but I was wrong.
From another stackoverflow question/answer: Tomcat does not recognize the MySQL .jar library
It's not going to work in WEB-INF/lib since the container needs access to the library, and, that is putting it in the classloader of one web app, not the container. While I would have imagined the CLASSPATH approach would work, it's not the standard way to do this. Perhaps there is some other snag that's preventing it from working.
I like to know how to configure my spring mvc configuration xml file to get connected to openshift postgresql 9.2 database. I already made changes on tomcat configuration file of path .openshift/config directory.
Just want to know how can I make connection to the openshift postgresql 9.2 from my spring mvc application deployed on openshift tomcat gear.
Everytime i deploy war on openshift tomcat i get error:
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:672)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1201)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:986)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.util.NoSuchElementException
java.util.ArrayList$Itr.next(ArrayList.java:834)
org.apache.jasper.compiler.Validator$ValidateVisitor.getJspAttribute(Validator.java:1385)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1262)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:876)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2429)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:895)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2429)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2435)
org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1841)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1201)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:986)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
What would be the reason for this?? whenever i run this war locally with local DB connection it run fine, but couldn't get what happens when i deploy on openshift tomcat?
In .openshift/config server.xml i have code under GlobalNamingResources tag is:
<Resource name="jdbc/postgresqldb" auth="Container" type="javax.sql.DataSource"
username="${env.OPENSHIFT_POSTGRESQL_DB_USERNAME}" password="${env.OPENSHIFT_POSTGRESQL_DB_PASSWORD}"
url="jdbc:postgresql://${env.OPENSHIFT_POSTGRESQL_DB_HOST}:${env.OPENSHIFT_POSTGRESQL_DB_PORT}/${env.OPENSHIFT_APP_NAME}"
driverClassName="org.postgresql.Driver" initialSize="5" maxWait="5000"
maxActive="120" maxIdle="5" validationQuery="select 1"
poolPreparedStatements="true">
</Resource>
and in .openshift/config context.xml under Context xml is:
<ResourceLink name="jdbc/postgresqldb" global="jdbc/postgresqldb" type="javax.sql.DataSource"/>
and in my spring mvc servlet-context.xml is:
<beans:bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/postgresqldb"/>
</beans:bean>
Check your JSP file for missing or wrong attributes values inside the html tags.
Spring MVC checks for well-formed html tags. If you missed fill any attributes or those attributes have wrong values, it won't run and will give you an error message related to JasperException.
I recommend using the spring tag namespace when using forms:
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:input type="text" class="form-control" placeholder="Login" maxlength="10" size="10" path="" name="login"/>
Eclipse in this case is very helpful because if something is wrong it will tell you.
I have a strange problem regarding TomEE and using a DataSource specified in tomee.xml.
It might be worth noting that I'm using Netbeans, TomEE and MySQL. Running on Ubuntu 13.04 (Xubuntu latest)
The tomee.xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<Resource id="booktablesDS" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql:localhost:3306/book_tables
UserName juser
Password jpassword
JtaManaged true
</Resource>
</tomee>
And a small codesnippet, testing the connection pool:
#Resource DataSource booktablesDS;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
Connection c = booktablesDS.getConnection();
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM BOOKS");
The output I'm getting from TomEE is:
SEVERE: null
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
Full stacktrace follows.
May 06, 2013 11:08:53 AM org.apache.catalina.util.LifecycleBase start
INFO: The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/EJBTest]] after start() had already been called. The second call will be ignored.
May 06, 2013 11:08:54 AM MainS processRequest
SEVERE: null
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at MainS.processRequest(MainS.java:35)
at MainS.doGet(MainS.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
at java.sql.DriverManager.getDriver(DriverManager.java:273)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 22 more
May 06, 2013 11:08:55 AM org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/EJBTest]
Basicly it feels like netbeans is deploying the project with another tomee.xml file? Disregarding the values in my tomee.xml, which is under tom-ee/conf/tomee.xml
Help would be awesome.
Looks like your url is wrong.
jdbc:mysql:localhost:3306/book_tables
should be
jdbc:mysql://localhost:3306/book_tables
Can you double-check whether the MySQL driver JAR is really there in tomee/lib folder.
Try to change your code like this:
#Resource(name = "booktablesDS", type = javax.sql.DataSource.class)
DataSource booktablesDS;
I am trying to create a Tomcat JNDI resource for MSSQL database.
This is how my resource string looks in tomcat context.xml file
<Resource
name="jdbc/FI/SD"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://LDIA;databaseName=SD"
validationQuery="Select 1"
maxActive="1" maxIdle="1" maxWait="10000"
user="rels"
password="hidden"
/>
This is the code snippet that i am using in Servlet to check datasource:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/FI/SD");
Connection conn = ds.getConnection();
but i am getting this error while creating connection at line 4,
how can i solve this:
org.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (Login failed for user ''. The user is not associated with a trusted SQL Server connection.)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at com.MyServlet.doGet(MyServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
Maybe user should be username instead?