Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to configure Struts connection pool

843838Apr 1 2006 — edited Apr 2 2006
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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 30 2006
Added on Apr 1 2006
1 comment
308 views