This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JBoss/WildFly and the fly likes problem in accessing in jndi  in jboss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "problem in accessing in jndi  in jboss" Watch "problem in accessing in jndi  in jboss" New topic

problem in accessing in jndi in jboss

narasimharao konjeti
Ranch Hand

Joined: Apr 26, 2003
Posts: 130
hi, i am accessing connection using jndi. i am unable to get the connection, it is giving exception call class cast exception, what might be the problem, can u explain, if writing code of mysql-ds.xml, and my jsp file,
mysql-ds.xml file


my jsp file
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/MGUDataSource");
Connection con = ds.getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from testdata");
out.println(" "+rs.getString(2));
}catch(Exception e){out.println(e.toString());
i am getting exception called, class cast exception,what might be the problem, can u explain.
waiting for reply.
thanx in advance.
nr konjeti

"Unwise to sweat petty stuff, wise to pet sweaty stuff."
norman richards
Ranch Hand

Joined: Jul 21, 2003
Posts: 367
Did you map the datasource in your jboss-web.xml? You should add a resource-ref that looks something like this: (refer to jboss-web_3_0.dtd to see the exact structure)

Then you should be able to lookup java:comp/env/jdbc/MGUDatasource from
your servlets, and (I assume) from your JSPs too.
I agree. Here's the link:
subject: problem in accessing in jndi in jboss
It's not a secret anymore!