struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "red phoenix" <rodphoe...@gmail.com>
Subject How to configure Struts connection pool
Date Sat, 01 Apr 2006 08:13:44 GMT
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:
<%@page import="java.sql.*"%>
<%@page import="javax.sql.DataSource"%>
<%@page 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!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message