• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in accessing in jndi in jboss

 
narasimharao konjeti
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
norman richards
Author
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic