Announcement

Collapse
No announcement yet.

DB Anbindung über Tomcat

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • DB Anbindung über Tomcat

    Hallo,
    leider gelingt es mir trotz etlicher Tutorials nicht meine DB-Anbindung über TOmcat abzuwickeln
    Ich habe bereit die Tomcat eigene server.xml editiert und zwar folgendermaßen:
    Code:
    <?xml version='1.0' encoding='utf-8'?>
    <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <!-- Note:  A "Server" is not itself a "Container", so you may not
         define subcomponents such as "Valves" at this level.
         Documentation at /docs/config/server.html
     -->
    <Server port="8005" shutdown="SHUTDOWN">
    
      <!--APR library loader. Documentation at /docs/apr.html -->
      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
      <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
      <Listener className="org.apache.catalina.core.JasperListener" />
      <!-- Prevent memory leaks due to use of particular java/javax APIs-->
      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
      <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
      <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
    
      <!-- Global JNDI resources
           Documentation at /docs/jndi-resources-howto.html
      -->
      <GlobalNamingResources>
        <!-- Editable user database that can also be used by
             UserDatabaseRealm to authenticate users
        -->
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
      </GlobalNamingResources>
    
      <!-- A "Service" is a collection of one or more "Connectors" that share
           a single "Container" Note:  A "Service" is not itself a "Container", 
           so you may not define subcomponents such as "Valves" at this level.
           Documentation at /docs/config/service.html
       -->
      <Service name="Catalina">
      
        <!--The connectors can use a shared executor, you can define one or more named thread pools-->
        <!--
        <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
            maxThreads="150" minSpareThreads="4"/>
        -->
        
        
        <!-- A "Connector" represents an endpoint by which requests are received
             and responses are returned. Documentation at :
             Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
             Java AJP  Connector: /docs/config/ajp.html
             APR (HTTP/AJP) Connector: /docs/apr.html
             Define a non-SSL HTTP/1.1 Connector on port 8080
        -->
        <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" />
        <!-- A "Connector" using the shared thread pool-->
        <!--
        <Connector executor="tomcatThreadPool"
                   port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" />
        -->           
        <!-- Define a SSL HTTP/1.1 Connector on port 8443
             This connector uses the JSSE configuration, when using APR, the 
             connector should be using the OpenSSL style configuration
             described in the APR documentation -->
        <!--
        <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
                   maxThreads="150" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS" />
        -->
    
        <!-- Define an AJP 1.3 Connector on port 8009 -->
        <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    
    
        <!-- An Engine represents the entry point (within Catalina) that processes
             every request.  The Engine implementation for Tomcat stand alone
             analyzes the HTTP headers included with the request, and passes them
             on to the appropriate Host (virtual host).
             Documentation at /docs/config/engine.html -->
    
        <!-- You should set jvmRoute to support load-balancing via AJP ie :
        <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
        --> 
        <Engine name="Catalina" defaultHost="localhost">
    
          <!--For clustering, please take a look at documentation at:
              /docs/cluster-howto.html  (simple how to)
              /docs/config/cluster.html (reference documentation) -->
          <!--
          <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
          -->        
    
          <!-- The request dumper valve dumps useful debugging information about
               the request and response data received and sent by Tomcat.
               Documentation at: /docs/config/valve.html -->
          <!--
          <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
          -->
    
          <!-- This Realm uses the UserDatabase configured in the global JNDI
               resources under the key "UserDatabase".  Any edits
               that are performed against this UserDatabase are immediately
               available for use by the Realm.  -->
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                 resourceName="UserDatabase"/>
    
          <!-- Define the default virtual host
               Note: XML Schema validation will not work with Xerces 2.2.
           -->
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true"
                xmlValidation="false" xmlNamespaceAware="false">
    
            <!-- SingleSignOn valve, share authentication between web applications
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
            -->
    
            <!-- Access log processes all example.
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
                   prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
            -->
    		<Context path="/dbcp" docBase="dbcp" debug="5" reloadable="true" crossContext="true">
    
    <Resource name="jdbc/TestDB" auth="Container"
       type="javax.sql.DataSource" removeAbandoned="true"
       removeAbandonedTimeout="30" maxActive="100"
       maxIdle="30" maxWait="10000" username="pcontrol_mnb1"
       password="xxxxxxxx"
       driverClassName="oracle.jdbc.driver.OracleDriver"
       url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid01-vip.ta.global)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid02-vip.ta.global)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=mid.ta.global)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"/>
    
    </Context>
          </Host>
        </Engine>
      </Service>
    </Server>
    Über eine Javaklasse versuche ich nun folgendermaßen eine Connection aus dem Pool zu erhalten:

    Code:
    	public static void main(String[] args) {
            DataSource ds = null;
              try {
                 Context ctx = new InitialContext();
                
                 Context envContext = (Context) ctx.lookup("java:/comp/env");
                 
                 ds = (DataSource) envContext.lookup("jdbc/TestDB");
                 
                 ResultSet rs = null;
                 Connection con = ds.getConnection();
                 rs = con.prepareStatement("SELECT * FROM PROCESS WHERE pid = 3860").executeQuery();
                 rs.next();
                 System.out.println(rs.getString(1));
                 rs.close();
                 con.close();
            } catch (NamingException | SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            
        }
    Darüber hinaus habe ich nichts gemacht. Jetzt bekomme ich allerdings immer eine javax.naming.NoInitialContextException, wo liegt mein Fehler?

  • #2
    Keine Webanwendung zu benutzen. Eine Webanwendung hat keine MAIN-Klasse, sie wird im Applicationserver deployt. Weiterhin gehört die DB-Verbindung unter

    <GlobalNamingResources>#

    angegeben

    http://tomcat.apache.org/tomcat-7.0-doc/index.html
    Christian

    Comment


    • #3
      Danke für deine Antwort, du hast selbstverständlich Recht, das war mir allerdings garnicht so bewusst mit der Main-Methode. Das brachte schonmal etwas Licht ins Dunkle.
      Ich habe allerdings noch immer ein kleines Problem. Folgende Exception tritt auf:
      Code:
      exception 
      
      org.apache.jasper.JasperException: javax.servlet.ServletException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
      	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
      	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
      	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      
      
      root cause 
      
      javax.servlet.ServletException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
      	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
      	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
      	org.apache.jsp.test_jsp._jspService(test_jsp.java:97)
      	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
      	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      
      
      root cause 
      
      org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
      	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
      	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
      	org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      	org.apache.jsp.test_jsp._jspService(test_jsp.java:81)
      	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
      	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      
      
      root cause 
      
      java.lang.NullPointerException
      	sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
      	sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
      	sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
      	java.sql.DriverManager.getDriver(DriverManager.java:273)
      	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
      	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
      	org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      	org.apache.jsp.test_jsp._jspService(test_jsp.java:81)
      	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
      	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      Ich habe die Ressource in der server.xml definiert:
      Code:
      <GlobalNamingResources>
          <!-- Editable user database that can also be used by
               UserDatabaseRealm to authenticate users
          -->
          <Resource name="UserDatabase" auth="Container"
                    type="org.apache.catalina.UserDatabase"
                    description="User database that can be updated and saved"
                    factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                    pathname="conf/tomcat-users.xml" />
      			  
      			  
      	<Resource name="jdbc/TestDB" auth="Container"
      				type="javax.sql.DataSource" removeAbandoned="true"
      				removeAbandonedTimeout="30" maxActive="100"
      				maxIdle="30" maxWait="10000" username="pcontrol_mnb1"
      				password="********"
      				driverClassName="oracle.jdbc.driver.OracleDriver"
      				url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid01-vip.ta.global)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid02-vip.ta.global)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=mid.ta.global)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"/>
        </GlobalNamingResources>
      Meine web.xml in meiner Webapp sieht folgendermaßen aus:

      Code:
      <resource-ref>
      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      </web-app>
      Ich bin mir nicht sicher aber fehlt da möglicherweise das <ResourceLink> tag? Oder hat diese Exception ganz andere Gründe? Ich benutze übrigens Tomcat 6

      Comment


      • #4
        Die Libs für Oracle gehören in das Lib-Verzeichnis des Tomcat
        Christian

        Comment


        • #5
          Danke für die schnelle Antwort, die ojdbc14.jar liegt allerdings bereits in dem Tomcat Lib-Verzeichnis oder muss ich darüber hinaus noch weitere jars hinzufügen?

          Comment


          • #6
            oracle.jdbc.OracleDriver

            sollte gegen

            driverClassName="oracle.jdbc.driver.OracleDriver"

            getauscht werden
            Christian

            Comment


            • #7
              Wenn ich dich richtig verstanden habe, soll ich mein Ressourceelement folgendermaßen verändern:
              Code:
              <Resource name="jdbc/TestDB" auth="Container"
              				type="javax.sql.DataSource" removeAbandoned="true"
              				removeAbandonedTimeout="30" maxActive="100"
              				maxIdle="30" maxWait="10000" username="******"
              				password="********"
              				driverClassName="oracle.jdbc.OracleDriver"
              				url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid01-vip.ta.global)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid02-vip.ta.global)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=mid.ta.global)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"/>
              Die Exception tritt allerdings weiterhin auf

              Comment


              • #8
                IMHO gehört in die web.xml eine
                resource-ref
                und in die server.xml im Context eine
                resource
                Christian

                Comment


                • #9
                  Hm also in der web.xml habe ich ja eine resource-ref:
                  Code:
                  <?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>HelloWorld</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>
                  <res-ref-name>jdbc/TestDB</res-ref-name>
                  <res-type>javax.sql.DataSource</res-type>
                  <res-auth>Container</res-auth>
                  </resource-ref>
                  </web-app>
                  Das ist meine komplette web.xml.
                  Bei der server.xml bin ich mir wegen dem Context jetzt nicht ganz sicher, den finde ich dort nicht, allerdings waren die GlabalNamingResources vordefiniert, so dass ich das da einfach reingelegt habe. hier mal die komplette server.xml:
                  Code:
                  <?xml version='1.0' encoding='utf-8'?>
                  <!--
                    Licensed to the Apache Software Foundation (ASF) under one or more
                    contributor license agreements.  See the NOTICE file distributed with
                    this work for additional information regarding copyright ownership.
                    The ASF licenses this file to You under the Apache License, Version 2.0
                    (the "License"); you may not use this file except in compliance with
                    the License.  You may obtain a copy of the License at
                  
                        http://www.apache.org/licenses/LICENSE-2.0
                  
                    Unless required by applicable law or agreed to in writing, software
                    distributed under the License is distributed on an "AS IS" BASIS,
                    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                    See the License for the specific language governing permissions and
                    limitations under the License.
                  -->
                  <!-- Note:  A "Server" is not itself a "Container", so you may not
                       define subcomponents such as "Valves" at this level.
                       Documentation at /docs/config/server.html
                   -->
                  <Server port="8005" shutdown="SHUTDOWN">
                  
                    <!--APR library loader. Documentation at /docs/apr.html -->
                    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
                    <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
                    <Listener className="org.apache.catalina.core.JasperListener" />
                    <!-- Prevent memory leaks due to use of particular java/javax APIs-->
                    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
                    <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
                    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
                    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
                  
                    <!-- Global JNDI resources
                         Documentation at /docs/jndi-resources-howto.html
                    -->
                    <GlobalNamingResources>
                      <!-- Editable user database that can also be used by
                           UserDatabaseRealm to authenticate users
                      -->
                      <Resource name="UserDatabase" auth="Container"
                                type="org.apache.catalina.UserDatabase"
                                description="User database that can be updated and saved"
                                factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                                pathname="conf/tomcat-users.xml" />
                  			  
                  			  
                  	<Resource name="jdbc/TestDB" auth="Container"
                  				type="javax.sql.DataSource" removeAbandoned="true"
                  				removeAbandonedTimeout="30" maxActive="100"
                  				maxIdle="30" maxWait="10000" username="*******"
                  				password="******"
                  				driverClassName="oracle.jdbc.OracleDriver"
                  				url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid01-vip.ta.global)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid02-vip.ta.global)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=mid.ta.global)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"/>
                    </GlobalNamingResources>
                  
                    <!-- A "Service" is a collection of one or more "Connectors" that share
                         a single "Container" Note:  A "Service" is not itself a "Container", 
                         so you may not define subcomponents such as "Valves" at this level.
                         Documentation at /docs/config/service.html
                     -->
                    <Service name="Catalina">
                    
                      <!--The connectors can use a shared executor, you can define one or more named thread pools-->
                      <!--
                      <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
                          maxThreads="150" minSpareThreads="4"/>
                      -->
                      
                      
                      <!-- A "Connector" represents an endpoint by which requests are received
                           and responses are returned. Documentation at :
                           Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
                           Java AJP  Connector: /docs/config/ajp.html
                           APR (HTTP/AJP) Connector: /docs/apr.html
                           Define a non-SSL HTTP/1.1 Connector on port 8080
                      -->
                      <Connector port="8080" protocol="HTTP/1.1" 
                                 connectionTimeout="20000" 
                                 redirectPort="8443" />
                      <!-- A "Connector" using the shared thread pool-->
                      <!--
                      <Connector executor="tomcatThreadPool"
                                 port="8080" protocol="HTTP/1.1" 
                                 connectionTimeout="20000" 
                                 redirectPort="8443" />
                      -->           
                      <!-- Define a SSL HTTP/1.1 Connector on port 8443
                           This connector uses the JSSE configuration, when using APR, the 
                           connector should be using the OpenSSL style configuration
                           described in the APR documentation -->
                      <!--
                      <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
                                 maxThreads="150" scheme="https" secure="true"
                                 clientAuth="false" sslProtocol="TLS" />
                      -->
                  
                      <!-- Define an AJP 1.3 Connector on port 8009 -->
                      <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
                  
                  
                      <!-- An Engine represents the entry point (within Catalina) that processes
                           every request.  The Engine implementation for Tomcat stand alone
                           analyzes the HTTP headers included with the request, and passes them
                           on to the appropriate Host (virtual host).
                           Documentation at /docs/config/engine.html -->
                  
                      <!-- You should set jvmRoute to support load-balancing via AJP ie :
                      <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
                      --> 
                      <Engine name="Catalina" defaultHost="localhost">
                  
                        <!--For clustering, please take a look at documentation at:
                            /docs/cluster-howto.html  (simple how to)
                            /docs/config/cluster.html (reference documentation) -->
                        <!--
                        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
                        -->        
                  
                        <!-- The request dumper valve dumps useful debugging information about
                             the request and response data received and sent by Tomcat.
                             Documentation at: /docs/config/valve.html -->
                        <!--
                        <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
                        -->
                  
                        <!-- This Realm uses the UserDatabase configured in the global JNDI
                             resources under the key "UserDatabase".  Any edits
                             that are performed against this UserDatabase are immediately
                             available for use by the Realm.  -->
                        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                               resourceName="UserDatabase"/>
                  
                        <!-- Define the default virtual host
                             Note: XML Schema validation will not work with Xerces 2.2.
                         -->
                        <Host name="localhost"  appBase="webapps"
                              unpackWARs="true" autoDeploy="true"
                              xmlValidation="false" xmlNamespaceAware="false">
                  
                          <!-- SingleSignOn valve, share authentication between web applications
                               Documentation at: /docs/config/valve.html -->
                          <!--
                          <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
                          -->
                  
                          <!-- Access log processes all example.
                               Documentation at: /docs/config/valve.html -->
                          <!--
                          <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
                                 prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
                          -->
                  
                        </Host>
                      </Engine>
                    </Service>
                  </Server>
                  Ist dort irgendwas wirklich falsch?

                  Comment


                  • #10
                    Irgendwie fehlt der Context in der server.xml....oder ich sehe den nicht
                    Christian

                    Comment


                    • #11
                      Wenn ich den Context im Host-Element hinzufüge ändert das leider auch nichts:
                      Code:
                      <?xml version='1.0' encoding='utf-8'?>
                      <!--
                        Licensed to the Apache Software Foundation (ASF) under one or more
                        contributor license agreements.  See the NOTICE file distributed with
                        this work for additional information regarding copyright ownership.
                        The ASF licenses this file to You under the Apache License, Version 2.0
                        (the "License"); you may not use this file except in compliance with
                        the License.  You may obtain a copy of the License at
                      
                            http://www.apache.org/licenses/LICENSE-2.0
                      
                        Unless required by applicable law or agreed to in writing, software
                        distributed under the License is distributed on an "AS IS" BASIS,
                        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                        See the License for the specific language governing permissions and
                        limitations under the License.
                      -->
                      <!-- Note:  A "Server" is not itself a "Container", so you may not
                           define subcomponents such as "Valves" at this level.
                           Documentation at /docs/config/server.html
                       -->
                      <Server port="8005" shutdown="SHUTDOWN">
                      
                        <!--APR library loader. Documentation at /docs/apr.html -->
                        <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
                        <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
                        <Listener className="org.apache.catalina.core.JasperListener" />
                        <!-- Prevent memory leaks due to use of particular java/javax APIs-->
                        <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
                        <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
                        <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
                        <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
                      
                        <!-- Global JNDI resources
                             Documentation at /docs/jndi-resources-howto.html
                        -->
                        <GlobalNamingResources>
                          <!-- Editable user database that can also be used by
                               UserDatabaseRealm to authenticate users
                          -->
                          <Resource name="UserDatabase" auth="Container"
                                    type="org.apache.catalina.UserDatabase"
                                    description="User database that can be updated and saved"
                                    factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                                    pathname="conf/tomcat-users.xml" />
                      			  
                      			 
                        </GlobalNamingResources>
                      
                        <!-- A "Service" is a collection of one or more "Connectors" that share
                             a single "Container" Note:  A "Service" is not itself a "Container", 
                             so you may not define subcomponents such as "Valves" at this level.
                             Documentation at /docs/config/service.html
                         -->
                        <Service name="Catalina">
                        
                          <!--The connectors can use a shared executor, you can define one or more named thread pools-->
                          <!--
                          <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
                              maxThreads="150" minSpareThreads="4"/>
                          -->
                          
                          
                          <!-- A "Connector" represents an endpoint by which requests are received
                               and responses are returned. Documentation at :
                               Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
                               Java AJP  Connector: /docs/config/ajp.html
                               APR (HTTP/AJP) Connector: /docs/apr.html
                               Define a non-SSL HTTP/1.1 Connector on port 8080
                          -->
                          <Connector port="8080" protocol="HTTP/1.1" 
                                     connectionTimeout="20000" 
                                     redirectPort="8443" />
                          <!-- A "Connector" using the shared thread pool-->
                          <!--
                          <Connector executor="tomcatThreadPool"
                                     port="8080" protocol="HTTP/1.1" 
                                     connectionTimeout="20000" 
                                     redirectPort="8443" />
                          -->           
                          <!-- Define a SSL HTTP/1.1 Connector on port 8443
                               This connector uses the JSSE configuration, when using APR, the 
                               connector should be using the OpenSSL style configuration
                               described in the APR documentation -->
                          <!--
                          <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
                                     maxThreads="150" scheme="https" secure="true"
                                     clientAuth="false" sslProtocol="TLS" />
                          -->
                      
                          <!-- Define an AJP 1.3 Connector on port 8009 -->
                          <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
                      
                      
                          <!-- An Engine represents the entry point (within Catalina) that processes
                               every request.  The Engine implementation for Tomcat stand alone
                               analyzes the HTTP headers included with the request, and passes them
                               on to the appropriate Host (virtual host).
                               Documentation at /docs/config/engine.html -->
                      
                          <!-- You should set jvmRoute to support load-balancing via AJP ie :
                          <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
                          --> 
                          <Engine name="Catalina" defaultHost="localhost">
                      
                            <!--For clustering, please take a look at documentation at:
                                /docs/cluster-howto.html  (simple how to)
                                /docs/config/cluster.html (reference documentation) -->
                            <!--
                            <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
                            -->        
                      
                            <!-- The request dumper valve dumps useful debugging information about
                                 the request and response data received and sent by Tomcat.
                                 Documentation at: /docs/config/valve.html -->
                            <!--
                            <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
                            -->
                      
                            <!-- This Realm uses the UserDatabase configured in the global JNDI
                                 resources under the key "UserDatabase".  Any edits
                                 that are performed against this UserDatabase are immediately
                                 available for use by the Realm.  -->
                            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                                   resourceName="UserDatabase"/>
                      
                            <!-- Define the default virtual host
                                 Note: XML Schema validation will not work with Xerces 2.2.
                             -->
                            <Host name="localhost"  appBase="webapps"
                                  unpackWARs="true" autoDeploy="true"
                                  xmlValidation="false" xmlNamespaceAware="false">
                      
                              <!-- SingleSignOn valve, share authentication between web applications
                                   Documentation at: /docs/config/valve.html -->
                              <!--
                              <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
                              -->
                      
                              <!-- Access log processes all example.
                                   Documentation at: /docs/config/valve.html -->
                              <!--
                              <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
                                     prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
                              -->
                      		<Context>
                      			<GlobalNamingResources>
                          <!-- Editable user database that can also be used by
                               UserDatabaseRealm to authenticate users
                          -->
                      			  
                      				<Resource name="jdbc/TestDB" auth="Container"
                      						type="javax.sql.DataSource" removeAbandoned="true"
                      						removeAbandonedTimeout="30" maxActive="100"
                      						maxIdle="30" maxWait="10000" username="*******"
                      						password="*********"
                      						driverClassName="oracle.jdbc.OracleDriver"
                      						url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid01-vip.ta.global)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=besrvup-mid02-vip.ta.global)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=mid.ta.global)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"/>
                      			</GlobalNamingResources>
                      		</Context>
                            </Host>
                          </Engine>
                        </Service>
                      </Server>
                      Liegt das Problem denn überhaupt darin? Also was ich aus der Exception rauslese ist ja, dass aus irgendeinem Grund die Url null ist. Wird die denn automatisch aus der server.xml gesetzt oder wie funktioniert das?

                      Comment


                      • #12
                        Hier mal ein Demoprojekt lediglich die LIB für MySQL ist nicht dabei, weil das ZIP dann zu groß für das Forum wäre

                        WebApplication1.zip

                        Starten mit

                        http://localhost:8080/WebApplication1/NewServlet

                        Ergibt auf dem Screen


                        Servlet NewServlet at /WebApplication1

                        Connection erfolgreich

                        Christian

                        Comment


                        • #13
                          Wo muss ich die denn genau hintun
                          Bin leider noch relativ neu auf diesem Gebiet. Also ich nehme an irgendwo ins Tomcat-Verzeichnis oder?

                          Comment


                          • #14
                            Das ist der Sourcecode. Welche IDE benutzt du?
                            Christian

                            Comment


                            • #15
                              Eclipse Juno aber importieren konnte ich das irgendwie nicht so wie ich das sonst immer mache...

                              Comment

                              Working...
                              X