Connecting Tech Pros Worldwide Forums | Help | Site Map

JSP, DataSource, Oracle...

mali_djuro
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi all,
i try to connect to the Oracle database through the DataSource, here is code
that i used

<%
....
String error = new String();
try {
java.util.Properties parms = new java.util.Properties();

error = "Defining Initial Context Factory...";
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.ejs.ns.jndi.CNInitialContextFactory") ;

error = " Defining Provider...";
parms.setProperty(Context.PROVIDER_URL, "iiop:///");

error = "Initializing InitialContext...";
ctx = new javax.naming.InitialContext(parms);

error = "Get DataSource from InitialContext...";
ds = (javax.sql.DataSource)ctx.lookup(ds_conn_string);

error = "Get Connection...";
con = ds.getConnection(ds_user, ds_password);

System.out.println("Datasource works!");

}
catch (Exception ne) {
System.out.println(error + "\n" + ne);
}
...
%>

When i start application on the server and try to access to the
database i got message in server log

Initializinig Initial Context...
Cannot instantiate class: com.ibm.ejs.ns.jndi.CNInitialContextFactory
[Root exception is java.lang.ClassCastException]

i tried also with com.ibm.websphere.naming.WsnInitialContextFactory
because i found that com.ibm.ejs.ns.jndi.CNInitialContextFactory
is deprecated, but i got same message

Initializinig Initial Context...
Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory
[Root exception is java.lang.ClassCastException]

i found so much examples on the web, that says it has to works
but i cannot do it.
is it possible that i have to set some special properties on my server?
is it something wrong in my code?

please help.
thanks in advance.





mali_djuro
Guest
 
Posts: n/a
#2: Jul 17 '05

re: JSP, DataSource, Oracle...


i forgot to say i work in JSP
[color=blue]
> Hi all,
> i try to connect to the Oracle database through the DataSource, here is code
> that i used
>
> <%
> ...
> String error = new String();
> try {
> java.util.Properties parms = new java.util.Properties();
>
> error = "Defining Initial Context Factory...";
> parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "com.ibm.ejs.ns.jndi.CNInitialContextFactory") ;
>
> error = " Defining Provider...";
> parms.setProperty(Context.PROVIDER_URL, "iiop:///");
>
> error = "Initializing InitialContext...";
> ctx = new javax.naming.InitialContext(parms);
>
> error = "Get DataSource from InitialContext...";
> ds = (javax.sql.DataSource)ctx.lookup(ds_conn_string);
>
> error = "Get Connection...";
> con = ds.getConnection(ds_user, ds_password);
>
> System.out.println("Datasource works!");
>
> }
> catch (Exception ne) {
> System.out.println(error + "\n" + ne);
> }
> ..
> %>
>
> When i start application on the server and try to access to the
> database i got message in server log
>
> Initializinig Initial Context...
> Cannot instantiate class: com.ibm.ejs.ns.jndi.CNInitialContextFactory
> [Root exception is java.lang.ClassCastException]
>
> i tried also with com.ibm.websphere.naming.WsnInitialContextFactory
> because i found that com.ibm.ejs.ns.jndi.CNInitialContextFactory
> is deprecated, but i got same message
>
> Initializinig Initial Context...
> Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory
> [Root exception is java.lang.ClassCastException]
>
> i found so much examples on the web, that says it has to works
> but i cannot do it.
> is it possible that i have to set some special properties on my server?
> is it something wrong in my code?
>
> please help.
> thanks in advance.[/color]
Closed Thread