Hi,
First of all we need not use "key" attribute in <data-source> tag until we
have more than one data source to be configured. So, try removing the "key"
attribute and use the getDataSource() method which is already defined in
DBCP.
DataSource db = getDataSource(request);
  You need not worry about all the naming lookups. That method will take
care of retrieving DataSource object . Even if you want to keep the "key"
attribute, then try using this,
DataSource db= getDataSource(request,key);

This should work for you. Let me know if you still face any issues.

Thanks,
Tarun.


On 4/1/06, red phoenix <[EMAIL PROTECTED]> wrote:
>
> 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