通用分页代码

接上通用分页util包

		package com.huangjie.util;
		import java.io.InputStream;import java.sql.Connection;
		import java.sql.DriverManager;
		import java.sql.ResultSet;import java.sql.SQLException;
		import java.sql.Statement;
		import java.util.Properties;
		public class DBHelper {	
		private static String driver;	
		private static String url;	
		private static String user;	
		private static String password;	
		static {// 静态块执行一次,加载 驱动一次	
			try {			InputStream is = DBHelper.class					.getResourceAsStream("config.properties");	
					Properties properties = new Properties();			properties.load(is);		
						driver = properties.getProperty("driver");		
							url = properties.getProperty("url");		
								user = properties.getProperty("user");			password = properties.getProperty("pwd");			
								Class.forName(driver);		
								} catch (Exception e) {			e.printStackTrace();	
										throw new RuntimeException(e);		}	}	/**	 * 获得数据连接对象	 * 	 * @return	 */
											public static Connection getConnection() {		
											try {			Connection conn = DriverManager.getConnection(url, user, password);		
												return conn;		} catch(SQLException e) {			e.printStackTrace();			throw new RuntimeException(e);		}	}	public static void close(ResultSet rs) {		if (null != rs) {			try {				rs.close();			} catch (SQLException e) {			
													e.printStackTrace();				throw new RuntimeException(e);		
														}	
															}	
															}	
															public static void close(Statement stmt) {	
																if (null != stmt) {			try {			
																	stmt.close();			} catch (SQLException e) {			
																		e.printStackTrace();			
																			throw new RuntimeException(e);		
																				}		}	}	public static void close(Connection conn) {	
																					if (null != conn) {		
																						try {				conn.close();		
																							} catch (SQLException e) {			
																								e.printStackTrace();		
																										throw new RuntimeException(e);
																													}		}	}	
																													public static void close(Connection conn, Statement stmt, ResultSet rs) {		
																													close(rs);		close(stmt);		
																													close(conn);
																														}	public static boolean isOracle() {
																																return "oracle.jdbc.driver.OracleDriver".equals(driver);
																																	}	public static boolean isSQLServer() {	
																																		return "com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(driver);	}		public static boolean isMysql() {		return "com.
				mysql.jdbc.Driver".equals(driver);
	}

	public static void main(String[] args) {
		Connection conn = DBHelper.getConnection();
		DBHelper.close(conn);
		System.out.println("isOracle:" + isOracle());
		System.out.println("isSQLServer:" + isSQLServer());
		System.out.println("isMysql:" + isMysql());
		System.out.println("数据库连接(关闭)成功");
	}
}		
**2.EncodingFilter类**					
									package com.huangjie.util;
									import java.io.IOException;
									import java.util.Iterator;
									import java.util.Map;
									import java.util.Set;
									import javax.servlet.Filter;
									import javax.servlet.FilterChain;
									import javax.servlet.FilterConfig;
									import javax.servlet.ServletException;
									import javax.servlet.ServletRequest;
									import javax.servlet.ServletResponse;
									import javax.servlet.http.HttpServletRequest;
									import javax.servlet.http.HttpServletResponse;
									public class EncodingFilter implements Filter {	
									private String encoding = "UTF-8";// 默认字符集	
									public EncodingFilter() {		
									super();	}	
								public void destroy() {	}	
								public void doFilter(ServletRequest request, ServletResponse response,		
									FilterChain chain) throws IOException, ServletException
									 {		
									 HttpServletRequest req = (HttpServletRequest) request;
									 		HttpServletResponse res = (HttpServletResponse) response;	
									 			// 中文处理必须放到 chain.doFilter(request, response)方法前面		res.setContentType("text/html;charset=" + this.encoding);	
									 				if (req.getMethod().equalsIgnoreCase("post")) {			req.setCharacterEncoding(this.encoding);
									 						} else {			
									 				Map map = req.getParameterMap();// 保存所有参数名=参数值(数组)的Map集合			Set set = map.keySet();// 取出所有参数名		
									 					Iterator it = set.iterator();			while (it.hasNext()) {		
									 							String name = (String) it.next();				
									 							String[] values = (String[]) map.get(name);// 取出参数值[注:参数值为一个数组]				for (int i = 0; i < values.length; i++) {			
									 									values[i] = new String(values[i].getBytes("ISO-8859-1"),							this.encoding);		
									 											}			}		}		chain.doFilter(request, response);	
									 											}	public void init(FilterConfig filterConfig) throws ServletException {		String s = filterConfig.getInitParameter("encoding");// 读取web.xml文件中配置的字符集		if (null != s && !s.trim().equals("")) {			this.encoding = s.trim();		}	}}		

**3.StringUtils类**
package com.huangjie.util;

public class StringUtils {
	// 私有的构造方法,保护此类不能在外部实例化
	private StringUtils() {
	}

	/**
	 * 如果字符串等于null或去空格后等于"",则返回true,否则返回false
	 * 
	 * @param s
	 * @return
	 */
	public static boolean isBlank(String s) {
		boolean b = false;
		if (null == s || s.trim().equals("")) {
			b = true;
		}
		return b;
	}
	
	/**
	 * 如果字符串不等于null或去空格后不等于"",则返回true,否则返回false
	 * 
	 * @param s
	 * @return
	 */
	public static boolean isNotBlank(String s) {
		return !isBlank(s);
	}

}
			
			**config.properties配置文件
			**			
				#oracle9i#driver=oracle.jdbc.driver.OracleDriver#url=jdbc:oracle:thin:@localhost:1521:orcl#user=scott#pwd=123#sql2005#driver=com.microsoft.sqlserver.jdbc.SQLServerDriver#url=jdbc:sqlserver://localhost:1433;DatabaseName=test1#user=sa#pwd=123#sql2000#driver=com.microsoft.jdbc.sqlserver.SQLServerDriver#url=jdbc:microsoft:sqlserver://localhost:1433;databaseName=unit6DB#user=sa#pwd=888888#mysqldriver=com.mysql.jdbc.Driverurl=jdbc:mysql://localhost:3306/bookshop?useUnicode=true&characterEncoding=UTF-8user=rootpwd=1234								
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值