I am trying to develop an application using Hibernate and Tomcat5.0.
What i am doing is
1.setting up the datasource in server.xml file in tomcat5.0 all the context variables etc.
2. trying to create a hibernate.cfg.xml file with "Use JNDI datasource" option in MyEclipseIDE.
I am getting an error "no initialization context"
exception raised is...javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.commons.dbc
p.BasicDataSourceFactory [Root exception is java.lang.ClassCastException]
If i use the same server.xml file and "Use JDBC driver" option for hibernate.cfg.xml file i am able to connect to the database and retrieve the information, but with JNDI i am not able to retrieve. Can please somebody help me from this problem.
and also i tried the same server.xml file with a jsp file having the call for initialcontext code like this below, it works fine i am able to get the data but only with hibernate i am not able to get the data. Please help.
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds =
(DataSource)ctx.lookup(
"java:comp/env/jdbc/TestDB");
if (ds != null) {
Connection conn = ds.getConnection();
if(conn != null) {
//foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =
stmt.executeQuery(
"select department from job_postings_new");
while(rst.next()) {
out.println(rst.getString(1));
}
conn.close();}}
Thanks in Advance.
[/b]
|