package student.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class DBUtil {
private static final String className = "com.mysql.jdbc.Driver";
private static final String user = "root";
private static final String password = "123456";
private static final String url = "jdbc:mysql://localhost:3306/student";
private static Connection connection;
static{
try {
Class.forName(className);
connection = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Connection getConnection(){
return connection;
}
public static ResultSet executeQuery(String sql){
try {
Statement st = connection.createStatement();
return st.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
public static ResultSet executeQuery(String sql, Object[] params){
try {
PreparedStatement pst = connection.prepareStatement(sql);
for(int i=0;i
pages = pagination.getPages();
if(url.contains("?"))
url += "&";
if(!url.endsWith("&"))
url += "?";
StringBuffer pageStr = new StringBuffer();
pageStr.append("");
pageStr.append("");
pageStr.append("");
return pageStr.toString();
}
}
class Pagination {
private int pageNo; //当前页号
private int pageCount;//总页数
private int floatCount;// 分页导航显示的页数
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getFloatCount() {
return floatCount;
}
public void setFloatCount(int floatCount) {
this.floatCount = floatCount;
}
public Pagination() {
super();
}
public Pagination(int pageNo, int pageCount, int floatCount) {
super();
this.pageNo = pageNo;
this.pageCount = pageCount;
this.floatCount = floatCount;
}
public List getPages(){
List pages = new ArrayList();
if(pageCount<=floatCount){
for(int i=1;i<=pageCount;i++){
pages.add(i + "");
}
}else if(pageNo<=floatCount/2){
for(int i=1;i<=floatCount;i++){
pages.add(i + "");
}
pages.add("...");
pages.add(pageCount + "");
}else if(pageNo>floatCount/2&&pageNo