2016-04-11 30 views
0

Üniversitedeki Java-EE için çok yeni ve Netbeans IDE'de veritabanı bağlantısıyla mükemmel bir şekilde çalışan projemi yapmaya çalışıyorum. NetBeans IDE (sunucu başlangıç ​​etki alanı etki alanı ve * .war dosya uygulama listesinde) ile başlatıldı ve sonra ben * .war dosya yerel ana sunucuya dağıtmak için çalıştı. projeyi localhost'ta başlatın: 8080, veritabanı bağlantısı başarısız oldu ve web uygulamam işe yaramayacaktı..war Dosyasının Dağıtılmasından Sonra, Glassfish'te Veritabanına Bağlanamadı

Bunu çözmek için herhangi bir fikri olan var mı? Exception picture

sunucusu günlük:

[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) 
]] 

bağlantı 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; 
} 
} 
+0

aracılığıyla EntityManager bir başvuru lütfen enjekte ederseniz Burada istisnaı göster –

+0

@AhmedGamal istisna resmini ekledi – user3469300

+0

null pointer istisnası, niçin db bağlantısı ile erro olduğundan emin olun, sunucu günlüğünü yükleyin lütfen –

cevap

0

aşağıda arama sözdizimi değişen deneyin:

ds = (DataSource)ctx.lookup("java:jdbc/fastfood"); 
1

Java EE size arama olmamalı siz el ile bağlantı kurarsınız ama bir veri kaynağı kullanın (https://docs.oracle.com/javase/8/docs/api/index.html?javax/sql/DataSource.html) uygulama sunucunuzda yapılandırıldı.

Veri kaynağını daha sonra burada açıklandığı gibi bileşeninize enjekte edebilirsiniz: https://docs.oracle.com/javaee/6/tutorial/doc/bncjk.html. Alternatif olarak veri kaynağını elde etmek için bir JNDI araması yapabilirsiniz.

bağlantınızın persistence.xml kendi JNDI adını vererek kazanılmış olacaktır veritabanı erişimi için JPA kullanıyor ve sadece @PersistenceContext açıklama (https://docs.oracle.com/javaee/7/api/javax/persistence/PersistenceContext.html)

İlgili konular