File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
Author

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

<datasources>
<local-tx-datasource>
<jndi-name>MGUDataSource</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/mgudb</connection-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<user-name></user-name>
<password></password>
</local-tx-datasource>
</datasources>

my jsp file
tyr{
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");
while(rs.next()){
out.println("<br>"+rs.getString(1));
out.println(" "+rs.getString(2));
}
out.println("<br>connection<br>");
}catch(Exception e){out.println(e.toString());
e.printStackTrace();
}
i am getting exception called, class cast exception,what might be the problem, can u explain.
waiting for reply.
thanx in advance.
cheers
nr konjeti


"Unwise to sweat petty stuff, wise to pet sweaty stuff."
norman richards
Author
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: http://aspose.com/file-tools
 
subject: problem in accessing in jndi in jboss