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
是不是这个类找错了啊.