0

Eclipse と Tomcat 7 を使用して oracle データベース 11g に接続する際に問題が発生しています。取得しているエラーコードは次のとおりです。

この javax.naming.NameNotFoundException: Name [myDataBaseName] is not bound in this Context を探します。[myDataBaseName] が見つかりません。

context.xml

<?xml version="1.0" encoding="UTF-8"?> <Context>
<Resource name="jdbc/mario"
auth="Container"
type="javax.sql.DataSource" 
driverClassName="oracle.jdbc.OracleDriver" 
url="jdbc:oracle:thin:@localhost:1521/XE"
username="mario" 
password="*135181mi" 
maxActive="20" 
maxIdle="30" 
maxWait="-1"/>

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"
> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
> version="2.5"<display-name>werbproject</display-name>  
> <welcome-file-list>
>     <welcome-file>index.html</welcome-file>
>     <welcome-file>index.htm</welcome-file>
>     <welcome-file>index.jsp</welcome-file>
>     <welcome-file>default.html</welcome-file>
>     <welcome-file>default.htm</welcome-file>
>     <welcome-file>default.jsp</welcome-file>   </welcome-file-list>
>      <resource-ref>   <description>Oracle Datasource</description>   <res-ref-name>jdbc/oracle</res-ref-name>  
> <res-type>javax.sql.DataSource</res-type>  
> <res-auth>Container</res-auth>   </resource-ref> 
> 
>    </web-app>

接続をテストする方法

    <html>
  `enter code here`<head>
    <%@ page errorPage="errorpg.jsp" 
             import="java.sql.*, 
                     javax.sql.*, 
                     java.io.*,
                     javax.naming.InitialContext,
                     javax.naming.Context" %>
  </head>
  <body>
    <h1>JDBC JNDI JSP Resource Test</h1>

<%
System.out.println("Console--testLine L14********************");
out.println("<BR>Browser--testLine L15");
String dsString = "java:/comp/env/myDataBaseName";

InitialContext initCtx = new InitialContext();
if ( initCtx == null ) {
   throw new Exception("Uh oh -- no context!");
}
DataSource ds = (DataSource) initCtx.lookup(dsString);
if ( ds == null ) {
   throw new Exception("Data source not found!");
}
System.out.println("Console--testLine L26");
out.println("<BR>Browser--testLine L27");

Connection conn  = null;

try {                   
    conn = ds.getConnection();
    if(conn == null) throw new Exception("No DB Connection");
    System.out.println("Console--testLine L34");
    out.println("<BR>Browser--testLine L35");

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select * from discipline");
    System.out.println("Console--testLine L39********************");
    out.println("<BR>Browser--testLine L40");
    out.println("<BR><BR><BR>"); 
     %>
    <table width=600 border=1> 
    <tr>
    <th align=left>Name</th>
    <th align=left>Discipline</th>
    <th align=left>School ID</th>
    </tr>
      <% 

    while (rset.next()) {         
        %>
        <tr><td> <%= rset.getString(1)  %></td>
        <td> <%= rset.getString(2)  %></td>
        <td> <%= rset.getInt(3)  %></td>
        </tr>
    <%  }
    rset.close();
    stmt.close();
    } catch(SQLException e)
     {
          // Do exception catch such as if connection is not made or 
          // query is not set up properly
          out.println("SQLException: " + e.getMessage() + "<BR>");
          while((e = e.getNextException()) != null)
          out.println(e.getMessage() + "<BR>");
     } catch(ClassNotFoundException e)
      {
          out.println("ClassNotFoundException: " + e.getMessage() + "<BR>");
      }
finally
   {
      //Clean up resources, close the connection.
      if(conn != null)
      {
         try
         {
            conn.close();
            initCtx.close();

         }
         catch (Exception ignored) {}
      }
   }
 %>
    </table>
  </body>
</html>

少し調べてみましたが、役立つ投稿が見つかりませんでした。どんな助けでも素晴らしいでしょう。

4

2 に答える 2

0

最初: がフォルダーcontext.xmlの下にあることを確認します。 2 番目: リソース名はです。META-INF
jdbc/mariomyDataBaseName

于 2013-10-27T20:31:31.220 に答える