Reputation: 1
I am very new to Java-EE in college and after trying to do my project which works perfectly fine with database connection in Netbeans IDE. I tried to deploy the *.war file to the local host server without the opening of Netbeans IDE ( server started with command as admin start-domain domain1 and the *.war file is in the application list) and after I start the project in the localhost:8080, the database connection failed and my web-app wouldn't work.
Does anyone has any idea how to solve it? Exception picture
server log:
[2016-04-11T16:24:50.888+0800] [Payara 4.1] [SEVERE] [] [] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1460363090888] [levelValue: 1000] [[
Mon Apr 11 16:24:50 SGT 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.]]
[2016-04-11T16:36:55.713+0800] [Payara 4.1] [SEVERE] [] [] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1460363815713] [levelValue: 1000] [[
Mon Apr 11 16:36:55 SGT 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.]]
[2016-04-11T16:50:35.840+0800] [Payara 4.1] [INFO] [] [javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors] [tid: _ThreadID=27 _ThreadName=http-listener-1(5)] [timeMillis: 1460364635840] [levelValue: 800] [[
RAR7099: The mcf being used to allocate the connection and the MCF in the pool are not equal.]]
[2016-04-11T16:50:35.844+0800] [Payara 4.1] [WARNING] [] [javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.allocator] [tid: _ThreadID=27 _ThreadName=http-listener-1(5)] [timeMillis: 1460364635844] [levelValue: 900] [[
RAR5038:Unexpected exception while creating resource for pool foodPool. Exception : javax.resource.spi.SecurityException: No password credential found]]
[2016-04-11T16:50:35.845+0800] [Payara 4.1] [WARNING] [] [javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors] [tid: _ThreadID=27 _ThreadName=http-listener-1(5)] [timeMillis: 1460364635845] [levelValue: 900] [[
RAR5117 : Failed to obtain/create connection from connection pool [ foodPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: No password credential found]]
[2016-04-11T16:50:35.846+0800] [Payara 4.1] [WARNING] [] [javax.enterprise.resource.resourceadapter.com.sun.gjc.spi] [tid: _ThreadID=27 _ThreadName=http-listener-1(5)] [timeMillis: 1460364635846] [levelValue: 900] [[
RAR5114 : Error allocating connection : [No password credential found]]]
[2016-04-11T16:50:35.848+0800] [Payara 4.1] [INFO] [] [] [tid: _ThreadID=27 _ThreadName=http-listener-1(5)] [timeMillis: 1460364635848] [levelValue: 800] [[
No password credential found]]
[2016-04-11T16:50:35.849+0800] [Payara 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=27 _ThreadName=http-listener-1(5)] [timeMillis: 1460364635849] [levelValue: 900] [[
StandardWrapperValve[login]: Servlet.service() for servlet login threw exception
java.lang.NullPointerException
at servlet.login.doPost(login.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Unknown Source)
]]
connection servlet:
package object;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Richard
*/
public class connection {
private InitialContext ctx;
public InitialContext getCtx() {
return ctx;
}
public void setCtx(InitialContext ctx) {
this.ctx = ctx;
}
public DataSource getDs() {
return ds;
}
public void setDs(DataSource ds) {
this.ds = ds;
}
public Connection getConn() {
return conn;
}
public void setConn(Connection conn) {
this.conn = conn;
}
public Statement getStmt() {
return stmt;
}
public void setStmt(Statement stmt) {
this.stmt = stmt;
}
public ResultSet getRs() {
return rs;
}
public void setRs(ResultSet rs) {
this.rs = rs;
}
private DataSource ds;
private Connection conn;
private Statement stmt;
private ResultSet rs;
public connection(){
try{
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("jdbc/fastfood");
}catch(NamingException ex)
{
}
}
public DataSource getDataSource(){
return ds;
}
}
Upvotes: 0
Views: 1425
Reputation: 5409
in Java EE you shouldn't lookup you connection manually but use a datasource (https://docs.oracle.com/javase/8/docs/api/index.html?javax/sql/DataSource.html) configured in your application server.
You can then inject the datasource into your component as described here: https://docs.oracle.com/javaee/6/tutorial/doc/bncjk.html. As an alternative you can do a JNDI lookup to acquire the datasource.
If you're using JPA for database access your connection would be acquired by giving its JNDI name in the persistence.xml and you'd only inject a reference to the EntityManager via @PersistenceContext annotation (https://docs.oracle.com/javaee/7/api/javax/persistence/PersistenceContext.html)
Upvotes: 1
Reputation: 13855
try with changing the lookup syntax as below:
ds = (DataSource)ctx.lookup("java:jdbc/fastfood");
Upvotes: 0