Hi,
If u are using websphare 3.0, First u will have to
configure the datasource for the oracle db using the
adminclient. Then use the following code to get the
connection. This code is for servlet, U can extend it
for JSP.

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class servletname extends HttpServlet
{

        private Context v3Ctx;
        private DataSource v3DS;
        private Connection con;

        public void init(ServletConfig servletconfig) throws
ServletException
        {
                super.init(servletconfig);
                try
                        {
                        Hashtable hashtable = new Hashtable();
                        hashtable.put("java.naming.factory.initial",
"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
                                v3Ctx = new InitialContext(hashtable);
                                v3DS =
(DataSource)v3Ctx.lookup("datasource name");
                        con = v3DS.getConnection("username",
"password");

                }
                        catch(Exception _ex)
                        {

                }
        }

}




*****************************************************
--- Triana Mendoza Federico <[EMAIL PROTECTED]> wrote:
>         Desire to use the DATASOURCE of Oracle in a
> server of  Websphere
> with the following JSP code:
>
>         <%@page import="java.io.*"%>
>         <%@page import="java.sql.*"%>
>         <%@page import="javax.sql.*"%>
>         <%@page import="java.util.*"%>
>         <%@page import="javax.naming.*"%>
>         <%@page import="javax.servlet.*"%>
>         <%@page
>
import="com.ibm.db2.jdbc.app.stdext.javax.sql.DataSource"%>
>         <%@page import="com.ibm.ejs.dbm.jdbcext.*"%>
>
>         <%
>                 String query = "select sysdate from
> dual";
>                 String URL   = "jdbc/TEST";
>
>                 try
>                 { Hashtable params = new
> Hashtable();
>
> params.put("java.naming.factory.initial",
> "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
>                   Context ctx = new
> InitialContext(params);
>
> com.ibm.db2.jdbc.app.stdext.javax.sql.DataSource ds
> =
>
(com.ibm.db2.jdbc.app.stdext.javax.sql.DataSource)ctx.lookup(URL);
>                   java.sql.Connection connection =
> ds.getConnection("usertest","passtest");
>
>                 } catch(Exception e){
>                         out.println(e);
>                 }
>         %>
>
>         but it marks an error to me when executing :
>
>                   java.sql.Connection connection =
> ds.getConnection("usertest","passtest");
>
>         obvious this defined " TEST " in the server.
> Some idea of why ??
>
> >        Thanks !!
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with
> body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets


=====
My home page http://www.geocities.com/siliconvalley/grid/4444

__________________________________________________
Do You Yahoo!?
Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free!
http://photos.yahoo.com/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to