Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Can't use DataSource from Oracle Application Server

Re: Can't use DataSource from Oracle Application Server

From: <Tural.Muradbeyli_at_gmail.com>
Date: 13 Feb 2007 22:30:22 -0800
Message-ID: <1171434622.307763.271690@j27g2000cwj.googlegroups.com>


On Feb 13, 6:58 pm, Tural.Muradbe..._at_gmail.com wrote:
> I have created DataSource on Oracle Application Server 10R Release 3
> (10.1.3) using Application Server Web Manager interface. When I test
> connection, the result is successfully. But when I use this data
> source in my application, error occurs:
>
> javax.naming.NameNotFoundException: java:comp/env/jdbc/ccs_uniutf1 not
> found in CCS
> com.oracle.naming.J2EEContext.getSubContext(J2EEContext.java:183)
>
> web.xml file of my application:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
> <filter>
> <filter-name>CharacterEncodingFilter</filter-name>
> <filter-class>az.unibank.Misc.CharacterEncodingFilter</filter-
> class>
> </filter>
>
> <filter-mapping>
> <filter-name>CharacterEncodingFilter</filter-name>
> <url-pattern>/servlet/*</url-pattern>
> </filter-mapping>
> <filter-mapping>
> <filter-name>CharacterEncodingFilter</filter-name>
> <url-pattern>*.jsp</url-pattern>
> </filter-mapping>
> <filter-mapping>
> <filter-name>CharacterEncodingFilter</filter-name>
> <url-pattern>*.html</url-pattern>
> </filter-mapping>
> <filter-mapping>
> <filter-name>CharacterEncodingFilter</filter-name>
> <url-pattern>*.htm</url-pattern>
> </filter-mapping>
>
> <!-- top of web.xml file -->
> <resource-ref>
> <description>Data Source for UNIUTF1.CCS</description>
> <res-ref-name>jdbc/ccs_uniutf1</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> <!-- rest of web.xml file -->
> </web-app>
>
> public static LoginManager Authorize(String login, String password)
> throws Exception
> {
> DataSource pool;
> Context env;
> Connection con = null;
> PreparedStatement ps = null;
> ResultSet rs = null;
> LoginManager lm = null;
> try
> {
> env = (Context)new InitialContext().lookup("java:comp/env");
> //Look up a DataSource, which represents a connection pool
> pool = (DataSource)env.lookup("jdbc/ccs_uniutf1");
> //Get a Connection from the connection pool
> con = pool.getConnection();
> ps = con.prepareStatement("SELECT name, login, password,
> email FROM cc_users WHERE login = ? AND disabled = 0");
> ps.setString(1, login);
> rs = ps.executeQuery();
> if(rs.next())
> {
> if(!password.equals(rs.getString("password")))
> {
> throw new InvalidPasswordException();
> }
> }
> else
> {
> throw new InvalidUserNameException(login);
> }
> lm = new LoginManager(rs.getString("name"),
> rs.getString("login"), rs.getString("email"));
> }
> finally
> {
> if(rs != null) rs.close();
> if(ps != null) ps.close();
> if((con != null) && (!con.isClosed())) con.close();
> }
> return lm;
> }
>
> http://serv2.imagehigh.com/imgss/5057806_ps1.png

I can found the solution.
For Tomcat I have to write:

Context env = (Context)new InitialContext().lookup("java:comp/env");

for Oracle iAS I have to write:

Context env = new InitialContext();

I develop and test the application on Tomcat 5.5, and then deploy them to Oracle iAS. Every time, I have to change code. I wrote static method which create and return connection, and everywhere I use this method to get new connection. I change line of context initialization only on one place, but it is not so good method. Is there any universal method? Or how can I determine Application Server, is this Tomcat or Oracle iAS? Received on Wed Feb 14 2007 - 00:30:22 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US