继续STRUTS下,数据源配置问题,昨天那个帖子被人恶意加了一大段广告,气愤啊!!
<!-- 这里是关于连接池的配置,使用SQLSERVER2000那个TYPE包是我自己下载打进去的,我用的环境是JDK1.6+TOMCAT6.X+ECLIPSE3.2.2 -->
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN " "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd ">
<struts-config>
<!-- Data Sources Configuration -->
<data-sources>
<data-source key= "sqlserver " type= "org.apache.commons.dbcp.BasicDataSource ">
<set-property property= "driverClassName " value= "com.microsoft.jdbc.sqlserver.SQLServerDriver "/>
<set-property property= "url " value= "jdbc:microsoft:sqlserver://localhost:1433;databasename=user "/>
<set-property property= "maxActive " value= "5 "/>
<set-property property= "user " value= "sa "/>
<set-property property= "password " value= "sa "/>
<set-property property= "autoCommit " value= "true "/>
</data-source>
</data-sources>
<!-- ActionForm Configuration-->
<form-beans>
<form-bean name= "formBean1 " type= "user.UserForm "> </form-bean>
</form-beans>
<!-- GlobalForward Configuration -->
<global-forwards>
<forward name= "successed " path= "/right.jsp "/>
<forward name= "failed " path= "/error.jsp "/>
</global-forwards>
<!-- Action Configuration -->
<action-mappings>
<action path= "/logincheck " type= "user.LoginCheck " name= "formBean1 " scope= "request " input= "/right.jsp "/>
</action-mappings>
</struts-config>
DBUSER类,具体的业务模型
package user;
import javax.sql.*;
import java.sql.*;
public class DBUser
{
DataSource dataSource;
public DBUser(DataSource dataSource)
{
this.dataSource = dataSource;
}
public boolean checkUser(String username,String password) throws Exception
{
Connection connection = null;
String StrSql;
ResultSet rs;
boolean result = false;
StrSql = "select * from users where username= ' " + username + " 'and password= ' " + password + " ' ";
try
{
connection = dataSource.getConnection();
Statement stmt = connection.createStatement();
rs = stmt.executeQuery(StrSql);
if(rs.next())
{
result = true;
}
}
catch(
SQLException ex)
{
ex.printStackTrace();
}
finally
{
if(connection !=