Nom [jdbc/mydb] n'est pas lié dans ce Contexte
je vois que cette question a déjà été soulevée à plusieurs reprises et je les ai toutes passées en revue. Mais je suis toujours incapable de résoudre mon problème.
quelqu'un Pourrait-il m'aider à identifier ce que je fais de mal?
j'obtiens le message d'erreur suivant lorsque j'essaie d'accéder à la base de données.jsp:
HTTP Status 500 - An exception occurred processing JSP page /database.jsp at line 24
type Exception report
message An exception occurred processing JSP page /database.jsp at line 24
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /database.jsp at line 24
21: <%
22: Context init = new InitialContext();
23: Context env = (Context) init.lookup("java:/comp/env/");
24: DataSource data = (DataSource) env.lookup("jdbc/mydb");
25: Connection conn = data.getConnection();
26: Statement stmt = conn.createStatement();
27:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
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)
root cause
javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [jdbc/mydb] 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.database_jsp._jspService(database_jsp.java:185)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
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)
voici quelques informations sur mon installation: Mon ordinateur tourne sur Mac OS X. Le serveur web est Tomcat version 7.0.52, installé sous /Utilisateurs/nom d'utilisateur/Dropbox/Server/apache-tomcat-7.0.52. J'essaie d'exécuter Derby 10.10.1.1 comme une base de données intégrée. J'ai copié derby.jar sous le répertoire / Users/username/Dropbox/Server/apache-tomcat-7.0.52 / lib. J'ai écrit ce qui suit dans mon CHEMIN de fichier (je ne suis pas sûr qu'il soit pertinent):
export DERBY_HOME=/Users/username/Dropbox/Server/apache-tomcat-7.0.52/lib
export PATH=$PATH:$DERBY_HOME/bin
Voici le contenu du site web.fichier xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</description>
</web-app>
contexte.xml
<?xml version='1.0' encoding='utf-8'?>
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
le serveur.xml
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<!-- Added by LC #2 @19/3/2014 -->
<!-- Global Datasource for Derby mydb database -->
<Resource name="jdbc/mydb"
type="javax.sql.DataSource" auth="Container"
description="Derby database for Stocktails"
maxActive="20" maxIdle="10" maxWait="-1"
username="" password=""
driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
url="jdbc:derby:/Users/username/Dropbox/Server/apache-tomcat-7.0.52/databases/mydb"/>
<!-- End #2 -->
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<!-- Added by LC #1 @19/3/2014 -->
<Context
docBase="ROOT" path="" debug="0"
reloadable="true">
</Context>
<!-- End #1 -->
</Host>
</Engine>
</Service>
</Server>
Enfin, voici la base de données.JSP page:
<html>
<head>
<title>Quote Query</title>
</head>
<body>
<h1>retrieve stock quotes</h1>
<h3>Choose Ticker(s):</h3>
<form method="get">
<input type="checkbox" name="ticker" value="AAPL">AAPL
<input type="checkbox" name="ticker" value="MSFT">MSFT
<input type="submit" value="Query">
</form>
<%
String[] tickers = request.getParameterValues("ticker");
if (tickers != null) {
%>
<%@ page import="javax.naming.*,java.sql.*,javax.sql.*" %>
<%
Context init = new InitialContext();
Context env = (Context) init.lookup("java:/comp/env/");
DataSource data = (DataSource) env.lookup("jdbc/mydb");
Connection conn = data.getConnection();
Statement stmt = conn.createStatement();
String sqlStr = "SELECT * FROM Quotes WHERE Ticker IN (";
sqlStr += "'" + tickers[0] + "'"; // First ticker
for (int i = 1; i < tickers.length; ++i) {
sqlStr += ", '" + tickers[i] + "'"; // Subsequent tickers need a leading commas
}
sqlStr += ") ORDER BY Date ASC";
// for debugging
System.out.println("Query statement is " + sqlStr);
ResultSet rset = stmt.executeQuery(sqlStr);
%>
<hr>
<form method="get" action="quotes.jsp">
<table border=1 cellpadding=5>
<tr>
<th>Ticker</th>
<th>Date</th>
<th>PriceOpen</th>
<th>PriceHigh</th>
<th>PriceLow</th>
<th>PriceClose</th>
<th>Volume</th>
<th>PriceAdjClose</th>
</tr>
<%
while (rset.next()) {
int id = rset.getInt("id");
%>
<tr>
<td><input type="checkbox" name="id" value="<%= id %>"></td>
<td><%= rset.getString("Ticker") %></td>
<td><%= rset.getString("Date") %></td>
<td>$<%= rset.getInt("PriceOpen") %></td>
<td><%= rset.getInt("PriceHigh") %></td>
<td><%= rset.getString("PriceLow") %></td>
<td><%= rset.getString("PriceClose") %></td>
<td>$<%= rset.getInt("Volume") %></td>
<td><%= rset.getInt("PriceAdjClose") %></td>
</tr>
<%
}
%>
</table>
<br>
<input type="submit" value="Order">
<input type="reset" value="Clear">
</form>
<a href="<%= request.getRequestURI() %>"><h3>Back</h3></a>
<%
rset.close();
stmt.close();
conn.close();
}
%>
</body>
</html>
Journal
Mar 21, 2014 7:57:26 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/lcazarre/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Mar 21, 2014 7:57:26 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Mar 21, 2014 7:57:28 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Mar 21, 2014 7:57:28 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 21, 2014 7:57:28 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 3227 ms
Mar 21, 2014 7:57:28 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 21, 2014 7:57:28 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
Mar 21, 2014 7:57:28 AM org.apache.catalina.realm.UserDatabaseRealm startInternal
SEVERE: Exception looking up UserDatabase under key UserDatabase
javax.naming.NameNotFoundException: Name [UserDatabase] is not bound in this Context. Unable to find [UserDatabase].
at org.apache.naming.NamingContext.lookup(NamingContext.java:819)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:253)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201)
at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
Mar 21, 2014 7:57:28 AM org.apache.catalina.realm.CombinedRealm startInternal
SEVERE: Failed to start "org.apache.catalina.realm.UserDatabaseRealm/1.0" realm
org.apache.catalina.LifecycleException: Failed to start component [Realm[UserDatabaseRealm]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201)
at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
Caused by: org.apache.catalina.LifecycleException: No UserDatabase component found under key UserDatabase
at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 17 more
Mar 21, 2014 7:57:31 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Users/lcazarre/Dropbox/Work/MS50/COMSM0104/Server/apache-tomcat-7.0.52/webapps/docs
Mar 21, 2014 7:57:32 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Users/lcazarre/Dropbox/Work/MS50/COMSM0104/Server/apache-tomcat-7.0.52/webapps/examples
Mar 21, 2014 7:57:33 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Users/lcazarre/Dropbox/Work/MS50/COMSM0104/Server/apache-tomcat-7.0.52/webapps/host-manager
Mar 21, 2014 7:57:33 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Users/lcazarre/Dropbox/Work/MS50/COMSM0104/Server/apache-tomcat-7.0.52/webapps/manager
Mar 21, 2014 7:57:34 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 21, 2014 7:57:34 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 21, 2014 7:57:34 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6321 ms
Merci, LC
3 réponses
<ResourceLink name="jdbc/mydb"
global="jdbc/mydb"
type="javax.sql.DataSource" />
pour ceux qui utilisent Tomcat avec Bitronix, cela corrigera le problème:
l'erreur indique qu'aucun gestionnaire n'a pu être trouvé pour votre source de données 'jdbc/mydb', vous devrez donc vous assurer que votre serveur tomcat se réfère à vos fichiers de configuration bitronix au besoin.
Dans le cas où vous êtes à l'aide de btm-config.propriétés et ressources.propriétés fichiers pour configurer la source de données, spécifiez ces deux arguments JVM tomcat:
(si vous avez déjà utilisé, assurez-vous que vos références sont correctes):
- btm.racine
- bitronix.tm.configuration
e.g.
-Dbtm.root="C:\Program Files\Apache Software Foundation\Tomcat 7.0.59"
-Dbitronix.tm.configuration="C:\Program Files\Apache Software Foundation\Tomcat 7.0.59\conf\btm-config.properties"
Maintenant, redémarrez votre serveur et consulter le journal.
vous mettez ressource-ref dans la balise de description dans le web.xml