JSP, DataSource, Oracle...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mali_djuro

    JSP, DataSource, Oracle...

    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.Prope rties parms = new java.util.Prope rties();

    error = "Defining Initial Context Factory...";
    parms.setProper ty(Context.INIT IAL_CONTEXT_FAC TORY,
    "com.ibm.ejs.ns .jndi.CNInitial ContextFactory" );

    error = " Defining Provider...";
    parms.setProper ty(Context.PROV IDER_URL, "iiop:///");

    error = "Initializi ng InitialContext. ..";
    ctx = new javax.naming.In itialContext(pa rms);

    error = "Get DataSource from InitialContext. ..";
    ds = (javax.sql.Data Source)ctx.look up(ds_conn_stri ng);

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

    System.out.prin tln("Datasource works!");

    }
    catch (Exception ne) {
    System.out.prin tln(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.CNInitialC ontextFactory
    [Root exception is java.lang.Class CastException]

    i tried also with com.ibm.websphe re.naming.WsnIn itialContextFac tory
    because i found that com.ibm.ejs.ns. jndi.CNInitialC ontextFactory
    is deprecated, but i got same message

    Initializinig Initial Context...
    Cannot instantiate class: com.ibm.websphe re.naming.WsnIn itialContextFac tory
    [Root exception is java.lang.Class CastException]

    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

    #2
    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.Prope rties parms = new java.util.Prope rties();
    >
    > error = "Defining Initial Context Factory...";
    > parms.setProper ty(Context.INIT IAL_CONTEXT_FAC TORY,
    > "com.ibm.ejs.ns .jndi.CNInitial ContextFactory" );
    >
    > error = " Defining Provider...";
    > parms.setProper ty(Context.PROV IDER_URL, "iiop:///");
    >
    > error = "Initializi ng InitialContext. ..";
    > ctx = new javax.naming.In itialContext(pa rms);
    >
    > error = "Get DataSource from InitialContext. ..";
    > ds = (javax.sql.Data Source)ctx.look up(ds_conn_stri ng);
    >
    > error = "Get Connection...";
    > con = ds.getConnectio n(ds_user, ds_password);
    >
    > System.out.prin tln("Datasource works!");
    >
    > }
    > catch (Exception ne) {
    > System.out.prin tln(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.CNInitialC ontextFactory
    > [Root exception is java.lang.Class CastException]
    >
    > i tried also with com.ibm.websphe re.naming.WsnIn itialContextFac tory
    > because i found that com.ibm.ejs.ns. jndi.CNInitialC ontextFactory
    > is deprecated, but i got same message
    >
    > Initializinig Initial Context...
    > Cannot instantiate class: com.ibm.websphe re.naming.WsnIn itialContextFac tory
    > [Root exception is java.lang.Class CastException]
    >
    > 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]

    Comment

    Working...