DB Anbindung über Tomcat

Br4ve

Bekanntes Mitglied
Hallo,
ich habe ja bereits schon einmal über JSPs versucht eine solche Verbindung herzustellen. Nun versuche ich das über eine Javaklasse, bekomme allerdings eine andere Fehlermeldung.

[XML]<?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="/Payment" docBase="C:\Applications\Payment">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="payment_log." suffix=".txt" timestamp="true"/>
<Resource auth="Container" name="jdbc/paymentDB" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/paymentDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc😱racle: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))))</value>
</parameter>
<parameter>
<name>password</name>
<value>xxxxxxxx</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>pcontrol_mnb1</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
</ResourceParams>
</Context>
</Host>
</Engine>
</Service>
</Server>
[/XML]

Ich denke das ist alles sehr standard, anpassen muss ich dort doch eigentlich eh nur 3 Zeilen oder?

Mein Java-Code ist folgender:

Java:
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/paymentDB");
			 
			 ResultSet rs = null;
			 Connection con = ds.getConnection();
			 rs = con.prepareStatement("SELECT * FROM PROCESS WHERE pid = 3860").executeQuery();
			 System.out.println(rs.getString(1));
			 rs.close();
			 con.close();
		} catch (NamingException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

Und ich bekomme folgende Fehlermeldung:
Code:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
	at javax.naming.InitialContext.lookup(InitialContext.java:411)
	at tagHandler.test.main(test.java:33)

Was mache ich da falsch? Muss ich den Context vorher definieren? Und wenn ja wie genau definiere ich den für den Tomcat auf dem localhost?
 
Zuletzt bearbeitet:
javax.naming.NoInitialContextException @ Java - tutorials.de: Tutorial, Forum, Anleitung & Hilfe
+ verlinkt
Zugriff auf SessionBbean auf externem JBoss @ Enterprise Java (JEE, J2EE, Spring & Co.) - tutorials.de: Tutorial, Forum, Anleitung & Hilfe

haben sowas wie
Java:
Properties p = new Properties();
p.put("javax.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
p.put("javax.naming.provider.url", urlName);           
p.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
InitialContext jndiContext = new InitialContext(p);
dabei, mit Konfigurationsdatei vielleicht nicht nötig, aber da sehe ich bei dir keinen javax.naming.factory.initial-Parameter,
der vielleicht nötig ist,

naja, genau kann ich es nicht sagen, nach einem Tag nur Trostanwort mit paar Suchergebnissen
 
Diese Threads kenne ich sehr gut 🙂 Leider hilft mir das nicht weiter, ob diese Properties bei einem lokalen Apache benötigt werden weiß ich nicht, da ich wie du bereits erwähnt hast das auch per Konfiguration vorgebe. Ich habe eben noch einen anderen Fehler bekommen, nachdem ich die web.xml meiner Anwendung um einen Listener erweitert habe, den konnte Tomcat beim Starten dann nicht finden, bin mir nicht sicher ob ich so eine Klasse selbst implemetieren muss dann. Die Tutorials zu diesem Thema sind sehr verschieden leider....
 
was spricht denn zumindest dagegen, wenigstens diesen einen Parameter beim InitialContext mitzugeben/ auszuprobieren?
nach API scheint daneben immer noch woanders nach weiteren Parametern gesucht zu werden

für XML-Files ist es in der Tat schwer, entsprechende Parameter vorzufinden,
etwa
'RE: [openjms-user] Tomcat+OpenJms: Naming Exception' - MARC

noch ein Quote, dann bin ich aber auch ruhig, grundsätzlich ziehe ich mich immer zurück auf: entweder gibt es überzeugende Tutorials, schnell gefunden, oder eine Technologie lieber gleich ignorieren

Context (Java 2 Platform SE v1.4.2)
public static final String INITIAL_CONTEXT_FACTORY

Constant that holds the name of the environment property for specifying the initial context factory to use. The value of the property should be the fully qualified class name of the factory class that will create an initial context. This property may be specified in the environment parameter passed to the initial context constructor, an applet parameter, a system property, or an application resource file. If it is not specified in any of these sources, NoInitialContextException is thrown when an initial context is required to complete an operation.

The value of this constant is "java.naming.factory.initial".
 
Ausprobiert habe ich schon ein paar Initial Context Definitionen. Ich weiß blos nicht welche Parameter ich selber nehmen muss....Copy&Paste funktioniert nicht :bae:
 
deine Aussage ist also, dass auch mit dem Parameter noch die Fehlermeldung kommt?
nun, das wäre eine neue Info,
ich habe es spasseshalber gerade selber in einem simplen Test-Programm ausprobiert,

und dabei ist natürlich zu beachten, dass es nach der Fehlermeldung um "java.naming.factory.initial" geht,
nicht wie von mir gepostet "javax.naming.factory.initial", vielleicht generell falsch im Link

Java:
public class Test
{

    public static void main(String[] args)
        throws Exception
    {
        Properties p = new Properties();
        // p.put("java.naming.factory.initial",
        // "org.jnp.interfaces.NamingContextFactory");
        InitialContext ctx = new InitialContext(p);

        Context envContext = (Context)ctx.lookup("java:/comp/env");
        envContext.lookup("jdbc/paymentDB");
    }
}
liefert bei mir die Fehlermeldung wie von dir anfangs gepostet,
mit dem put kommt eine andere Fehlermeldung, das scheint also irgendwas zu bewirken,

ob gut oder schlecht ist damit natürlich nicht gesagt
 
Nachdem mir mein Apache zunächst mal komplett abgeschmiert ist nach meinen Bemühungen, habe ich eine handvoll neue Erkenntnisse sammeln können. Da eine Webapp keine main-Klasse hat und sie vom Applicationsserver deployt wird, ist es schonmal nicht möglich an die im TOmcat für die Webapp bereitgestellte Resource zu kommen.
Ich habe darüber hinaus noch ein paar Veränderungen vorgenommen an der 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" />
			  
			 
  </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>

Meine web.xml sieht folgendermaßen aus
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 sollte eigentlich auch richtig sein so.
Dann mein aufrufender javacode bzw. meine JSP um in der Webapp zu bleiben:
Java:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %>

<% 
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

DataSource ds = (DataSource)
envCtx.lookup("jdbc/TestDB");
Connection conn = ds.getConnection();
ResultSet rs = conn.prepareStatement("SELECT * FROM PROCESS WHERE pid = 3860").executeQuery();
while(rs.next()){
	System.out.println(rs.getString(1));
}
rs.close();
conn.close();
%>
</body>
</html>

Leider bekomme ich noch immer eine Exception, allerdings eine Andere:
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 werde daraus einfach nicht schlau und weiß mir nicht mehr zu helfen. Wenn ich doch scheinbar irgendwas so elementares vergesse wieso sieht das dann niemand? :bahnhof:
 
Oracle TNS sagt mir garnichts, wenn dann benutze ich das wohl unbewusst 😛
Referenzieren tue ich doch aber in der web.xml genau wie in der Dokumentation :rtfm:
 
Hi,

nur mit Copy&Paste wirst du nicht weit kommen, musst schon ein bsísschen verstehen was du da vorhast bzw. was das da ist das du nutzt, nciht böse gemeint.

Als erstes würde ich keine TNS nutzen sondern eine normale JDBC URL.
Dann würde ich einfach mla die in der server.xml angelegte JNDI Ressource eben über die context.xml referenzieren und in der web.xml einbinden wollen.
 
Ich weiß leider herzlich wenig über die Datenbank mit der ich arbeite, außer das Schema was sich darauf befindet. Die url habe ich auch nur gegeben bekommen, daher gab es keinen Grund sich damit irgendwie auseinander zu setzen bisher. Wenn ich die Datenbank durch eine Java-Klasse anspreche funktionierte sie ja auch, aber scheinbar hat Tomcat damit Probleme. Eine einfach Möglichkeit die url "umzuwandeln" gibt es wohl nicht oder?
 
Nachdem ich mir die Stacktraces angesehen habe, sehe ich da etwas von der JDBOC/ODBC Brücke... wie kommt dass da hin?

Wenn die TNS stimmt und nutzbar ist, dann konzentriere dich erstmal auf andere Probleme.

Tipp:
Entpacke dir einen sauberen Tomcat und probiere das ganze nochmal mit einer frischen, unversauten Konfig.
 
Das wird nichts helfen, denn hierbei handelt es sich augenscheinlich um einen "Bug" seitens Tomcat. Ich weiß garnicht weshalb ich die "url cannot be null"-Exception noch nicht eher gegoogelt habe, vielleicht weil ich zu Anfang des Threads eine Andere bekam, aber nun denn. Cannot create JDBC driver of class... Aus diesem Thread beispielsweise geht hervor, dass dieses Problem wohl sehr oft auftritt und über viele Tomcatversionen stattfindet. Mir gelang es noch nicht das Problem zu beheben, da ich momentan wenig Zeit dafür habe, allerdings kann ich jetzt wohl Formfehler meinerseits ausschließen.
 
Der "Bug" sitzt eindeutig vor dem Computer... Tomcat ist i.O.

Du kannst gerne den Fehler Tomcat in die Schuhe schieben, aber die Wahrheit ist das nicht 😉

Nochmal: Wie kommt da die JDBC-ODBC Brücke rein?
 
Nochmal: Wie kommt da die JDBC-ODBC Brücke rein?

Gute Frage, soweit ich weiß sollte das ein anderer sein.... Jetzt bin ich ein wenig verwirrt. ???:L
In der server.xml steht doch bei url:
Code:
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))))
Das bedeutet doch, dass der oracle thin driver benutzt wird oder nicht?
Anstelle einer JDBC ODBC Bridge.....
 
Ich meine du weisst nicht wirklich was du da gemacht hast bzw. was da passiert.

Deine Exceptions/Stacktraces passen nicht zu dem Code denn du gezeigt hast.

Wenn du jetzt keine Zeit/Motivation mehr aufbringst ist das OK und sogar verständlich, man lernt JEE/WebApps nciht einfach so nebenbei, ist 'ne komplexe Geschichte, verglichen mit PHP zB.
Wie dem auch sei, das ist kein Bug in Tomcat, JNDI Datasources funktionieren prächtig.
 
Ich meine du weisst nicht wirklich was du da gemacht hast bzw. was da passiert.

Deine Exceptions/Stacktraces passen nicht zu dem Code denn du gezeigt hast.

Wenn du jetzt keine Zeit/Motivation mehr aufbringst ist das OK und sogar verständlich, man lernt JEE/WebApps nciht einfach so nebenbei, ist 'ne komplexe Geschichte, verglichen mit PHP zB.
Wie dem auch sei, das ist kein Bug in Tomcat, JNDI Datasources funktionieren prächtig.

Natürlich ist es extrem ermüdend den immergleichen Fehler mittlerweile bestimmt fast 12 std zu suchen, um so erfreulicher allerdings dann wie jetzt zu einer vielleicht auch nicht ganz idealen Lösung zu kommen.
Meine laienhafte Lösung und Analalyse:
Die Exceptions passen sehr wohl zu dem Code, insofern als dass Tomcat die Ressource aus irgendeinem Grund nicht lesen kann scheinbar. Ich habe in meinem META-INF Verzeichnis der Webapp eine context.xml die folgendermaßen aussieht hinzugefügt:
[XML]<?xml version="1.0" encoding="UTF-8"?>
<Context>

<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.driver.OracleDriver"
url="jdbc😱racle: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>[/XML]

Jetzt funktioniert meine JSP und ich bekomme tatsächlich Datensätze zurück. Eigentlich müsste es ja aber auch mit der context.xml im Tomcat Verzeichnis gehen oder? Ist das nicht eigentlich gängige Praxis? Mir sind zur Zeit keine Nachteile meiner Methode bekannt aberich meine gelesen zu haben es sei anders schöner....
 

Neue Themen


Zurück
Oben