This is a discussion on Re: Can't use DataSource from Oracle Application Server within the Oracle Miscellaneous forums, part of the Oracle Database category; --> On Feb 13, 6:58 pm, Tural.Muradbe...@gmail.com wrote: > I have created DataSource on Oracle Application Server 10R Release 3 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Feb 13, 6:58 pm, Tural.Muradbe...@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(J2EECo ntext.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? |