标题:[求助]Struts中配置数据源问题.
取消只看楼主
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
 问题点数:0 回复次数:0 
[求助]Struts中配置数据源问题.

JB2006环境下编写的:

在struts-config.xml文件中data-sources部分代码为
<data-sources>
<data-source key="sql" type="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<set-property property="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver" />
<set-property property="url" value="Jdbc:Odbc:Users" />
</data-source>
</data-sources>
但是"org."这里总是被提示有错误,我们老师说这里不要紧,连的Access,
然后我在类中取出这里的连接配置,代码为:
package userlogin;

import java.sql.*;
import javax.sql.DataSource;
public class CheckUserBean {
Connection conn = null;
ResultSet rs = null;
String username, userpasswd;
boolean flag = false;

public CheckUserBean(DataSource ds)
{
try
{
conn = ds.getConnection();
}
catch (SQLException e)
{
e.printStackTrace();
}
}

public boolean verifyUser(String userName, String passwd)
{
String sql = "select * from users where username='" + username +
"' and userpasswd='" + userpasswd + "'";
try
{
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next())
{
flag = true;
}
if (conn != null)
{
try
{
conn.close();
conn = null;
}
catch (SQLException e)
{
System.err.print(e.getMessage());
}
}
}
catch (SQLException e)
{
e.printStackTrace();
}
return flag;
}
}

然后再在一个Action中获取这个数据源
UserActionForm userActionForm = (UserActionForm) form;
String username = userActionForm.getUserName();
String userpasswd = userActionForm.getUserPasswd();
ServletContext context = servlet.getServletContext(); //取得上下文环境
DataSource ds = (DataSource) context.getAttribute("sql");

CheckUserBean cu = new CheckUserBean(ds);
boolean flag = cu.verifyUser(username, userpasswd);
if (flag)
return mapping.findForward("succee");
else
return mapping.findForward("error");

运行后,登录页面能够出来,输入用户名和密码后出错错误提示
description The server encountered an internal error () that prevented it from fulfilling this request.
请问这是怎么回事啊.

感觉是:
org.apache.tomcat.dbcp.dbcp.BasicDataSource
是不是这个类配置错了啊.是找的在JB自带的Tomcat中
D:\JBuilder2006\thirdparty\jakarta-tomcat-5.5.9\common\lib\naming-factory-dbcp\org\apache\tomcat\dbcp\dbcp\BasicDataSource.class
是不是这个类找错了啊.

搜索更多相关主题的帖子: 数据源 Struts 
2006-10-17 14:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-96901-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.105353 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved