users@glassfish.java.net

trying to make connection pooling in GlassFish V3

From: <forums_at_java.net>
Date: Sat, 11 Feb 2012 06:52:55 -0600 (CST)

HI ,

i'm trying to make connection pooling in GlassFish V3 , but i'm getting this
exception :

 javax.servlet.ServletException: No object bound to name
java:comp/env/myJDBCResourceName

Here are my configurations :

Pool name : test2

JDBC Resources ---> Jndi name : jdbc/myJDBCResourceName and associated with
test2 

Hers is my code :

public void init() throws ServletException { // TODO Auto-generated method
stub Context env = null; try { env = (Context) new
InitialContext().lookup("java:comp/env"); pool = (DataSource)
env.lookup("jdbc/myJDBCResourceName"); if (pool == null) { throw new
ServletException("'unknown DataSource"); } } catch (NamingException ne) {
throw new ServletException(ne.getMessage()); } }     protected void
doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException { try { Connection con = pool.getConnection();
         Statement st = con.createStatement(); ResultSet rs =
st.executeQuery("select menuid from ivrlog where datelog>='20120205' ;");
System.out.println("excuting the query"); while (rs.next()) {
System.out.println(rs.getString(0)); } } catch (SQLException e) { // TODO
Auto-generated catch block e.printStackTrace(); } catch
(InstantiationException e) { e.printStackTrace(); } catch
(IllegalAccessException e) { // TODO Auto-generated catch block
e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO
Auto-generated catch block e.printStackTrace(); } }  

and this part in the WEB.xml:

  <res-ref-name>sherifPool</res-ref-name>

  <res-type>javax.sql.DataSource</res-type>

  <res-auth>Container</res-auth>

  <res-sharing-scope>Shareable</res-sharing-scope>

Anything i'm missing ?

 

 

 



--
[Message sent by forum member 'sshehab']
View Post: http://forums.java.net/node/883446