tomcat jndi jdbc connection pooling

jodevelopment

Grünschnabel
Hallo zusammen,
bei dem Versuch eine Tomcat JSP/Servlet Webanwendung auf JNDI JDBC / Sql Server 2005 Connection Pooling umzustellen bekomme ich die Fehlermeldung:

Code:
SCHWERWIEGEND: Servlet.service() for servlet jsp threw exception
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1130)
	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
	at org.apache.jsp.test_005fJDBC_005fPool_jsp._jspService(test_005fJDBC_005fPool_jsp.java:80)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Unknown Source)

Die Konfiguration sieht wie folgt aus:

META-INF/context.xml :
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/testweb" docBase="testweb" debug="5" reloadable="true" crossContext="true">
	<Resource
	   name="jdbc/sqlserver"
	   auth="Container"
	   type="javax.sql.DataSource"
	   maxActive="100"
	   maxIdle="30"
	   maxWait="10000"
	   username="sa"
	   password=""
	   driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
	   url="jdbc:sqlserver://localhost:1433;DatabaseName=testDB"
   />
</Context>

web.xml
HTML:
<?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_2_5.xsd"
   version="2.5">
      
   <display-name>Eine Web - Applikation</display-name>

   <resource-ref>
	  <description>
		Resource reference to a factory for java.sql.Connection
		instances that may be used for talking to a particular
		database that is configured in the Context
		configurartion for the web application.
	  </description>
	  <res-ref-name>
		jdbc/sqlserver
	  </res-ref-name>
	  <res-type>
		javax.sql.DataSource
	  </res-type>
	  <res-auth>
		Container
	  </res-auth>
	</resource-ref>
	
</web-app>

Im Tomcat\lib Verzeichnis befindet sich die benötigte Datei sqljdbc.jar

Zum Testen benutze ich folgende JSP:

Code:
<%@page import="java.sql.*"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<html>
<body>
<%
	Context initCtx=new InitialContext();
	if ( initCtx == null )
	{
		out.println("No Context <br>");
	}
	else
	{
		out.println("Context Found <br>");
		Context envContext = (Context) initCtx.lookup("java:/comp/env");
		DataSource db = (DataSource) envContext.lookup("jdbc/sqlserver");
		
		if ( initCtx == null )
		{
			out.println("No Informix JDBC JNDI Found <br>");
		}
		else
		{
			out.println("Informix JDBC JNDI Found <br>");
			Connection conn = db.getConnection();
			out.println("Got Connection <br>");
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery("SELECT * FROM Customers");  
			// Assuming there is table in your databse and one of the column is order id
			out.println("order id <br> ================================= <br> ");
			
			while(rs.next()){
			  out.print(rs.getString(1)+"<br>");
			}
			
			out.println("==========Test Completed======================= <br> ");
			rs.close();
			stmt.close();
			conn.close();
		}
	}
%>
  </body>
</html>

Der Fehler kommt bei der Zeile: Connection conn = db.getConnection();
Der vorherige lookup gelingt.

Habe jetzt schon einige Stunden im Netz nach gesucht und vieles ausprobiert,
aber nichts was weiterbringt....


Vielleicht hat jemand eine Idee.

Danke
Jo
 
Hallo zusammen,

nach einem ganzen Tag Fehlersuche klappt es heute morgen nach dem Neustart auf einmal.

You never know.......



Weg zur Erkenntnis : durch falsche Rückschlüsse zum richtigen Ergebnis kommen - oder umgekehrt!
 
Zurück