# Oracle DataSource im JBOSS ---> ClassCastException



## shAGGie (9. Apr 2008)

hab eine oracle datasource in mein jboss 4.2.2.GA eingerichtet.

um die datenbank testweise mal auszulesen habe ich diese paar zeilen code geschrieben


```
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="de.kvdrfehl.db.*"%>
<%@page import="java.sql.*"%>
<%@page import="javax.naming.*" %>
<%@page import="javax.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>KVdR Fehlermanagement</title>
</head>
<body>
<%

	Context initCtx = new InitialContext();
	Context envCtx = (Context) initCtx.lookup("java:OracleDS");
	DataSource ds = (DataSource) envCtx.lookup("OracleDS");
	Connection con = ds.getConnection();

	try{	
		PreparedStatement ps = con.prepareStatement("select * from tbl_vsnr"); 
		ResultSet rs = ps.executeQuery(); 
	
		while(rs.next()){ 
		System.out.println("P_ID "+rs.getInt(1)+" VSNR "+rs.getString(2)); 
		}	
	}catch(Exception e){ 
		e.printStackTrace(); 
	} 
%>	
</body>
</html>
```

doch auf die zeile 
	
	
	
	





```
Context envCtx = (Context) initCtx.lookup("java:OracleDS");
```
 bekomme ich diese ClassCastException


```
java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource
	at org.apache.jsp.Main_jsp._jspService(Main_jsp.java:72)
	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:373)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
	at java.lang.Thread.run(Thread.java:595)
```

meine oracle-ds.xml


```
<datasources>
  <local-tx-datasource>
    <jndi-name>OracleDS</jndi-name> 
    <connection-url>jdbc:oracle:thin:@02-S2K3:1521:****</connection-url> 
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> 
    <user-name>********</user-name> 
    <password>********</password> 
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name> 
    <metadata>
      <type-mapping>Oracle9i</type-mapping> 
    </metadata>
  </local-tx-datasource>
</datasources>
```


----------



## kochWaldi (11. Apr 2008)

Du machst ja fast alles richtig, aber wenn Du eine Datasource bekommst, dann sollte man Sie auch nutzen.

So sollte es gehen.  :meld: 

```
Context initCtx = new InitialContext(); 

DataSource ds = (DataSource) initCtx.lookup("java:OracleDS");
Connection con = ds.getConnection();
```

Grüße


----------



## shAGGie (13. Apr 2008)

yo super danke, auf gnau das gleiceh bin ihc mitn freund später dann gekommen. aber trotzdem danke

ciao


----------

