javax.servlet.ServletException: javax.naming.NameNotFoundException: Име [jdbc/data] не е обвързано в този контекст. Не може да се намери [jdbc]

Видях, че този въпрос е задаван и друг път, но не мога да отстраня проблема.

Искам да се свържа с mysql, присъстващ в локалната база данни на моя компютър, който има Windows 7, използвайки Eclipse Java EE IDE за уеб разработчици и инсталиран Apache Tomcat 7.0.70, но когато стартирам кода ми се срива с грешка:

HTTP Status 500 - javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [jdbc/ldata] is not bound in this Context. Unable to find [jdbc].

type Exception report

message javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [jdbc/data] is not bound in this Context. Unable to find [jdbc].

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [jdbc/data] is not bound in this Context. Unable to find [jdbc].
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:556)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:462)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [jdbc/ldata] is not bound in this Context. Unable to find [jdbc].
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:151)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.naming.NameNotFoundException: Name [jdbc/ldata] is not bound in this Context. Unable to find [jdbc].
    org.apache.naming.NamingContext.lookup(NamingContext.java:819)
    org.apache.naming.NamingContext.lookup(NamingContext.java:167)
    org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:97)
    javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    org.apache.naming.NamingContext.lookup(NamingContext.java:842)
    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(Unknown Source)
    confDataSource.ConnectToDatabase.getConnection(ConnectToDatabase.java:18)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:98)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.70 logs.

Apache Tomcat/7.0.70

дневник

lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:HelloWorld' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ReadGet' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ReadPost' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Redirect' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:JSP' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:JSPRedirect' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:JSPInUnFile' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Include' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:For' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:forward' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:UseBean' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:JDBC' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:DataSourceObject' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:RetrievingAndModifying' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:PreparedStatement' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:confDataSource' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:confDataSource2' did not find a matching property.
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server version:        Apache Tomcat/7.0.70
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server built:          Jun 15 2016 16:27:45 UTC
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server number:         7.0.70.0
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: OS Name:               Windows 7
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: OS Version:            6.1
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Architecture:          amd64
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Java Home:             B:\Program Files\Java\jre7
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: JVM Version:           1.7.0_80-b15
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: JVM Vendor:            Oracle Corporation
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: CATALINA_BASE:         B:\Users\Danilo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: CATALINA_HOME:         B:\Program Files\Apache Software Foundation\Tomcat 7.0
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dcatalina.base=B:\Users\Danilo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
lug 06, 2016 3:40:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dcatalina.home=B:\Program Files\Apache Software Foundation\Tomcat 7.0
lug 06, 2016 3:40:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dwtp.deploy=B:\Users\Danilo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
lug 06, 2016 3:40:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Djava.endorsed.dirs=B:\Program Files\Apache Software Foundation\Tomcat 7.0\endorsed
lug 06, 2016 3:40:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dfile.encoding=Cp1252
lug 06, 2016 3:40:32 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAZIONI: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: B:\Program Files\Java\jre7\bin;B:\Windows\Sun\Java\bin;B:\Windows\system32;B:\Windows;C:\app\Danilo\product\11.2.0\dbhome_1\bin;B:\Windows\system32;B:\Windows;B:\Windows\System32\Wbem;B:\Windows\System32\WindowsPowerShell\v1.0\;B:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;B:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Programmi\Anaconda;C:\Programmi\Anaconda\Scripts;B:\Program Files (x86)\Skype\Phone\;B:\Program Files\Java\jdk1.7.0_79\bin;.
lug 06, 2016 3:40:32 PM org.apache.coyote.AbstractProtocol init
INFORMAZIONI: Initializing ProtocolHandler ["http-bio-8080"]
lug 06, 2016 3:40:32 PM org.apache.coyote.AbstractProtocol init
INFORMAZIONI: Initializing ProtocolHandler ["ajp-bio-8009"]
lug 06, 2016 3:40:32 PM org.apache.catalina.startup.Catalina load
INFORMAZIONI: Initialization processed in 1140 ms
lug 06, 2016 3:40:32 PM org.apache.catalina.core.StandardService startInternal
INFORMAZIONI: Starting service Catalina
lug 06, 2016 3:40:32 PM org.apache.catalina.core.StandardEngine startInternal
INFORMAZIONI: Starting Servlet Engine: Apache Tomcat/7.0.70
lug 06, 2016 3:40:33 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:33 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFORMAZIONI: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [139] milliseconds.
lug 06, 2016 3:40:33 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:34 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:34 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:34 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:34 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:35 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:35 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:35 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:35 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:36 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:36 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:36 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:36 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:37 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:37 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:37 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:37 PM org.apache.catalina.startup.TldConfig execute
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
lug 06, 2016 3:40:37 PM org.apache.coyote.AbstractProtocol start
INFORMAZIONI: Starting ProtocolHandler ["http-bio-8080"]
lug 06, 2016 3:40:37 PM org.apache.coyote.AbstractProtocol start
INFORMAZIONI: Starting ProtocolHandler ["ajp-bio-8009"]
lug 06, 2016 3:40:37 PM org.apache.catalina.startup.Catalina start
INFORMAZIONI: Server startup in 5546 ms
lug 06, 2016 3:40:39 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [jsp] in context with path [/confDataSource] threw exception [javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [jdbc/data] is not bound in this Context. Unable to find [jdbc].] with root cause
javax.naming.NameNotFoundException: Name [jdbc/data] is not bound in this Context. Unable to find [jdbc].
    at org.apache.naming.NamingContext.lookup(NamingContext.java:819)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
    at org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:97)
    at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:842)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:830)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:830)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:830)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at confDataSource.ConnectToDatabase.getConnection(ConnectToDatabase.java:18)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:98)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

WebContent/META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <ResourceLink global="jdbc/data" name="jdbc/data" type="javax.sql.DataSource" />
</Context>

server.xml (в етикета GlobalNamingResources)

<Resource name="jdbc/data" auth="Container" type="javax.sql.DataSource" 
      maxActive="15" maxIdle="3" maxWait="10000"
      username="root" password="password" 
      url="jdbc:mysql://localhost:3306/" driverClassName="com.mysql.jdbc.Driver" 
            />

WebContent/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <resource-ref>
            <description>DB Connection</description>
            <res-ref-name>jdbc/data</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
  </resource-ref>
  <display-name>confDataSource</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

confDataSource.ConnectToDatabase.java

package confDataSource;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConnectToDatabase {
    private Connection conn;
    private Context ctx = null;

    public ConnectToDatabase(){}

    public Connection getConnection() throws NamingException, SQLException{
        ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/data");
        conn = ds.getConnection();
        return conn;
    }

    public boolean closeConnection(Connection conn) throws SQLException {
        if (conn != null) {
            conn.close();
            return true;
        }
        return false;
    }

}

Благодаря на всеки, който иска да ми помогне


person Kuroi    schedule 06.07.2016    source източник
comment
Опитахте ли търсенето без префикса java:/comp/env/?   -  person nitind    schedule 06.07.2016


Отговори (1)


опитайте това в server.xml

<Resource name="jdbc/data" auth="Container" type="javax.sql.DataSource" 
      maxActive="15" maxIdle="3" maxWait="10000"
      username="root" password="password" 
      url="jdbc:mysql://localhost:3306/data" driverClassName="com.mysql.jdbc.Driver" 
            />

промених url в горния код, където данните са името на вашата база данни.

person yash    schedule 06.07.2016
comment
Опитах, но винаги излиза същата грешка, въпреки че данните са името на базата данни - person Kuroi; 06.07.2016
comment
това е грешка в конфигурацията на tomcat. използвайте mkyong.com/tomcat/how- to-configure-mysql-datasource-in-tomcat-6 за извършване на конфигурация - person yash; 06.07.2016
comment
но по този начин данните за достъп до базата данни ще останат в Context, но бих искал те да са в GlobalNamingResources. възможно ли е да се направи това? иначе ще пробвам по друг начин - person Kuroi; 06.07.2016