;
type="com.yourcompany.struts.action.ProductShowAction">
<forward name="success" path="/index.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
Struts1.2实现MySQL数据库分页(3)
时间:2011-09-07
第三步:创建包和数据库连接
在SRC下创建 dao , dbtool, vo,factory四个包
在dbtool包里主要放访问JDBC数据库的连接类等。下面提供我用的JavaBean类。
DBConnection.java的内容如下:
package com.yourcompany.dbtool;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
/**
* 这是一个连接数据的单模式
* @author 树下无影
*
*/
public class DBConnection {
private static DBConnection instance;
private String driver;
private String url;
private String user;
private String password;
private DBConnection() throws Exception{
InputStream in=getClass().getClassLoader().getResourceAsStream(
"com/yourcompany/dbtool/database.properties");
Properties prop=new Properties();
prop.load(in);
driver=prop.getProperty("driver");
url=prop.getProperty("url");
user=prop.getProperty("user");
password=prop.getProperty("password");
try{
Class.forName(driver);
}catch(Exception e)
{
System.out.println("数据库初始化出错");
throw e;
}
System.out.println(driver+" "+url+" "+user+" "+password);
}
public static DBConnection getInstance(){
try{
if(instance==null){
instance=new DBConnection();
}
return instance;
}catch(Exception e){
System.out.println("实例化单模子出错");
return null;
}
}
public Connection getConnection()throws SQLException{
Connection con;
try{
con=DriverManager.getConnection(url, user, password);
}catch(SQLException e){
System.out.println("Connection连接出错");
throw e;
}
return con;
}
public void closeConnection(Connection con){
if(con!=null){
try{
con.close();
}catch(SQLException e)
{
System.out.println("关闭Connection连接出错");
}
}
}
}
Struts1.2实现MySQL数据库分页(4)
时间:2011-09-07
这里用一个配置文件,database.properties 里面存放数据库的UR |