I use struts-1.2.9,and want to configure a connection pool,so I configure
struts-config.xml file
<struts-config>
  <data-source key="bb1" type="org.apache.commons.dbcp.BasicDataSource">
  <set-property property="driverClassName" value="
sun.jdbc.odbc.JdbcOdbcDriver" />
  <set-property property="url" value="jdbc:odbc:SMS"/>
  <set-property property="maxActive" value="5" />
  <set-property property="username" value="administrator" />
  <set-property property="password" value="123" />
  <set-property property="autoCommit" value="true" />
 </data-source>
 ....
</struts-config>

Then I use this configure in a jsp file,like follows:
<[EMAIL PROTECTED] import="java.sql.*"%>
<[EMAIL PROTECTED] import="javax.sql.DataSource"%>
<[EMAIL PROTECTED] import="javax.naming.*"%>
<html>
<body>
<%
 try{
  Context initCtx=new InitialContext();
  System.out.println("ok");
  DataSource db = (DataSource)initCtx.lookup("java:comp/env/jdbc/bb1");
  System.out.println("db="+db);
  Connection conn = db.getConnection();
  System.out.println("conn="+conn);
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery("SELECT * FROM abc");
  out.println("User-list"+"<br>");
  while(rs.next()){
   out.print(rs.getString(1)+"<br>");
  }
  rs.close();
  stmt.close();
  conn.close();
 }catch(Exception e){
  out.print(e);
 }
%>
</body>
</html>

When I run this jsp file,it raise follow errors:
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Where error is in my code? Please give me some examples about how to
configure connection pool in Struts and how to call this connection in JSP
file and JavaBean.

Thanks in advance!

Reply via email to