Java课程设计:考勤管理系统(附源码+调试)

发布于:2023-07-04 ⋅ 阅读:(104) ⋅ 点赞:(0)

JAVA/JSP考勤管理系统:

一、主要功能

     1. 在登陆界面可以选择登录方式,包括员工、管理员和经理三种身份登录方式,不同的身份登录验证通过之后就会分别跳转到不同的界面,并且获得不同的权限去进行相应的操作。

     2.员工可以根据实际情况在这个界面发出各种申请,例如加班、请假、调休、出差等,将各项信息填入到对应的文本框中点击提交按钮,然后就等待经理的审批。

     3.经理登录成功之后跳转到此界面,可以对自己的信息进行修改,能够查询员工信息、考勤记录,还能够对员工提交的各种申请进行审批。

完整源码:https://pan.baidu.com/s/1vQmgdIKXXi-1uac-ZF-0Sw    提取码:9k7d

登陆界面:提供三种登陆方式(管理员、员工、经理),每一种登陆方式对应不同的操作权限,下面的展示就按管理员的来。

考勤管理主界面:主要的功能有系统用户管理、部门信息管理、员工信息管理、经理信息管理、考勤时间管理、考勤补录管理、考勤记录管理、考勤信息统计、系统设置。(由于功能较多,我们就不一一展示了,这里我们着重介绍员工信息管理和考勤信息统计)

员工信息管理又分为:员工信息添加、员工信息查询(可按工号、姓名查询并且支持导出EXCEL)

考勤信息统计(请假信息统计、休息信息统计、加班信息统计、课休信息统计、出差信息统计)

数据库表设计:

部分源码展示:

登录界面(login.jsp):

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@page import="util.Info"%>
<%@page import="dao.CommDAO"%>
<%@page import="util.PageManager"%>
<html>
<head>
<title>考勤管理系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-repeat: repeat-x;
	background-color: #215B9A;
}
.STYLE6 {color: #FFFFFF}
.STYLE5 {color: #CCFFCC;
	font-size: 26pt;
}
.STYLE9 {color: #ffffff; font-size:12px}
-->
</style>
</head>
<script type="text/javascript">
 <%
String error = (String)request.getAttribute("error"); 
if(error!=null)
{
 %>
 alert("用户名或密码错误");
 <%}%>
 
  <%
String random = (String)request.getAttribute("random"); 
if(random!=null)
{
 %>
 alert("验证码错误");
 <%}%>
 
 popheight = 39;

function check()
{
	if(document.form1.username.value=="" || document.form1.pwd.value=="" )
	{
		alert('请输入完整');
		return false;
	}
}

           function loadimage(){ 
document.getElementById("randImage").src = "image.jsp?"+Math.random(); 
} 

           
           </script>     
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="1004" height="750" border="0" align="center" cellpadding="0" cellspacing="0" background="images/login.jpg" id="__01">
  <tr>
    <td height="293" colspan="3"><p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <table width="84%" height="56" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="56"><div style="font-family:宋体; color:#FFFFFF;WIDTH: 100%; FONT-WEIGHT: bold; FONT-SIZE:30px ; margin-top:5pt">
            <div align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;考勤管理系统</div>
        </div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td width="434" rowspan="2">&nbsp;</td>
    <td width="289" height="152"><form action="jspm53178kqglxtsx?ac=adminlogin&a=a" method="post" name="form1" style="display: inline"><table width="205" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="44" height="30"><span class="STYLE9">用户:</span></td>
        <td height="30" colspan="2"><input name="username" type="text" id="username" style="width:100px; height:16px; border:solid 1px #000000; color:#666666"></td>
      </tr>
      <tr>
        <td height="30"><span class="STYLE9">密码:</span></td>
        <td height="30" colspan="2"><input name="pwd" type="password" id="pwd" style="width:100px; height:16px; border:solid 1px #000000; color:#666666"></td>
      </tr>
      <tr>
        <td height="30"><span class="STYLE9">权限:</span></td>
        <td height="30" colspan="2"><select name="cx" id="cx">
            <option value="管理员">管理员</option>
			<option value="经理">经理</option>
			<option value="员工">员工</option>
          </select>
        </td>
      </tr>
     <!-- <tr>
        <td height="30"><span class="STYLE9">验证码:</span></td>
        <td width="59" height="30"><input name="pagerandom" type="text" id="pagerandom" style=" height:20px; border:solid 1px #000000; color:#666666; width:50px" />
        <td width="102"><a href="javascript:loadimage();"><img alt="看不清请点我!" name="randImage" id="randImage" src="image.jsp" width="60" height="20" border="1" align="absmiddle"> </a></td>
      </tr>-->
      <tr>
        <td height="30" colspan="3"><input type="submit" name="Submit" value="登陆" onClick="return check();" style="color:#000000;width:80px;height: 24px; border:0px;line-height:24px; font-size:12px;margin-right: 5px; cursor:pointer">
            <input type="reset" name="Submit2" value="重置" style="color:#000000;width:80px;height: 24px; border:0px;line-height:24px; font-size:12px;margin-right: 5px; cursor:pointer" ></td>
      </tr>
    </table>
	</form></td>
    <td width="281" rowspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

 数据库连接代码:

package dao;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.Info;


public class CommDAO
{
	public static String dbname = "";
	public static String dbtype = "";
	
	public static Connection conn = null;
	
	public CommDAO()
	{
		conn = this.getConn();
	}



         //给字段做加减法
	 public void jiajian(String tablename,String colname,String id,String num)
	 {
		 HashMap map = this.getmap(id, tablename);
		 String value = map.get(colname).toString();
		 if(value.equals(""))value="0";
		 int i = Integer.parseInt(value);
		 int j = Integer.parseInt(num);
		 commOper("update "+tablename+" set "+colname+" = "+(i+j)+" where id="+id);
	 }
	
	 //	该方法返回一个table 用于流动图片
	public String DynamicImage(String categoryid,int cut,int width,int height){

		StringBuffer imgStr = new StringBuffer();
		StringBuffer thePics1 = new StringBuffer();
		StringBuffer theLinks1 = new StringBuffer();
		StringBuffer theTexts1 = new StringBuffer();
	
		imgStr.append("<div id=picViwer1  style='background-color: #ffffff' align=center></div><SCRIPT src='js/dynamicImage.js' type=text/javascript></SCRIPT>\n<script language=JavaScript>\n");
		thePics1.append("var thePics1=\n'");
		theLinks1.append("var theLinks1='");
		theTexts1.append("var theTexts1='");
		
		List<HashMap> co = this.select("select * from xinwentongzhi where shouyetupian<>'' and shouyetupian<>'null'  and shouyetupian  like '%.jpg' order by id desc",1,6);
		int i = co.size();
		
		int j = 0; 
		for(HashMap b:co)
		{
			j++; 
		int id = Integer.parseInt(b.get("id").toString()) ;
		String title = Info.subStr(b.get("biaoti").toString(), 21) ;
		
		String url = ""+b.get("shouyetupian");
		
		String purl = "gg_detail.jsp?id="+b.get("id");
		
		if(j!=i){
		thePics1.append(url.replaceAll("\n", "")+"|");
		theLinks1.append(purl+"|");
		theTexts1.append(title+"|");
		}
		if(j==i)
		{
			thePics1.append(url.replaceAll("\n", ""));
			theLinks1.append("gg_detail.jsp?id="+b.get("id"));
			theTexts1.append(title);
		}
		
		}
	   thePics1.append("';");
		
		theLinks1.append("';");
		theTexts1.append("';");
		imgStr.append(thePics1+"\n");
		imgStr.append(theLinks1+"\n");
		imgStr.append(theTexts1+"\n");
		imgStr.append("\n setPic(thePics1,theLinks1,theTexts1,"+width+","+height+",'picViwer1');</script>");
		return imgStr.toString();
	}
	
	 


		public HashMap getmap(String id,String table)
		{
			List<HashMap> list = new ArrayList();
			try {
				Statement st = conn.createStatement();
				//System.out.println("select * from "+table+" where id="+id);
			    ResultSet rs = st.executeQuery("select * from "+table+" where id="+id);
			    ResultSetMetaData rsmd = rs.getMetaData();
	            while(rs.next())
			    {
			    	HashMap map = new HashMap();
			    	int i = rsmd.getColumnCount();
			    	for(int j=1;j<=i;j++)
			    	{
			    		if(!rsmd.getColumnName(j).equals("ID"))
			    		{
			    			String str = rs.getString(j)==null?"": rs.getString(j);
			    			if(str.equals("null"))str = "";
			    			map.put(rsmd.getColumnName(j), str);
			    		}
			    		else
			    			map.put("id", rs.getString(j));
			    	}
			    	list.add(map);
			    }
			    rs.close();
			    st.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return list.get(0);
		}
		
		public HashMap getmaps(String nzd,String zdz,String table)
		{
			List<HashMap> list = new ArrayList();
			try {
				Statement st = conn.createStatement();
				//System.out.println("select * from "+table+" where "+nzd+"='"+zdz+"'");
			    ResultSet rs = st.executeQuery("select * from "+table+" where "+nzd+"='"+zdz+"'");
			    ResultSetMetaData rsmd = rs.getMetaData();
	            while(rs.next())
			    {
			    	HashMap map = new HashMap();
			    	int i = rsmd.getColumnCount();
			    	for(int j=1;j<=i;j++)
			    	{
			    		if(!rsmd.getColumnName(j).equals("ID"))
			    		{
			    			String str = rs.getString(j)==null?"": rs.getString(j);
			    			if(str.equals("null"))str = "";
			    			map.put(rsmd.getColumnName(j), str);
			    		}
			    		else
			    			map.put("id", rs.getString(j));
			    	}
			    	list.add(map);
			    }
			    rs.close();
			    st.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return list.get(0);
		}
		
		
		 
		public String insert(HttpServletRequest request,HttpServletResponse response, String tablename,HashMap extmap,boolean alert,boolean reflush,String tzurl)
		{
			extmap.put("addtime", Info.getDateStr());
			if(request.getParameter("f")!=null){
			HashMap typemap = new HashMap();
			ArrayList<String> collist = new ArrayList();
			String sql = "insert into "+tablename+"(";
			
		 
			Connection conn = this.getConn();
			try {
				Statement st = conn.createStatement();
			    ResultSet rs = st.executeQuery("select * from "+tablename);
			    ResultSetMetaData rsmd = rs.getMetaData();
	            int i = rsmd.getColumnCount();
			    	 
			    	for(int j=1;j<=i;j++)
			    	{
			    	if(rsmd.getColumnName(j).equals("id"))continue;
					if(rsmd.getColumnName(j).equals("ID"))continue;
					if(rsmd.getColumnName(j).equals("iD"))continue;
					if(rsmd.getColumnName(j).equals("Id"))continue;
			    	typemap.put(rsmd.getColumnName(j)+"---", rsmd.getColumnTypeName(j));
			    	collist.add(rsmd.getColumnName(j));
	    	    	sql+=rsmd.getColumnName(j)+",";
			    	}
			    	sql = sql.substring(0,sql.length()-1);
			    
			    sql+=") values(";
			    rs.close();
			    st.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			Enumeration enumeration = request.getParameterNames();
			String names = ",";
			while(enumeration.hasMoreElements())
			{
			names += enumeration.nextElement().toString()+",";
			}
			try {
				Statement st = conn.createStatement();
			    for(String str:collist)
			    {
			    	if(names.indexOf(","+str+",")>-1)
			    	{
			    		String[] values = request.getParameterValues(str);
			    		String value="";
			    		for(String vstr:values)
			    		{
			    			if(vstr==null)vstr="";
			    			if(vstr.equals("null"))vstr="";
			    			if(vstr.trim().equals(""))continue;
			    			
			    			if(request.getParameter(vstr)!=null&&!"".equals(request.getParameter(vstr))&&request.getParameter("dk-"+str+"-value")!=null)
			    			{
			    				String dkv = request.getParameter(vstr);
			    				String dknamevalue = request.getParameter("dk-"+str+"-value");
			    				vstr+=" - "+dknamevalue+":"+dkv;
			    			}
			    			
			    			value+=vstr+" ~ ";
			    			
			    			
			    			
			    		}
			    		if(value==null)value="";
		    			if(value.equals("null"))value="";
			    		if(value.length()>0)value=value.substring(0,value.length()-3);
			    		 
			    	    if(typemap.get(str+"---").equals("int"))
			    	    {
			    		sql+=(value.equals("")?-10:value)+",";
			    	    }else{
			    	    sql+="'"+(value.equals("null")?"":value)+"',";
			    	    }
			    	}else{
			    		if(typemap.get(str+"---").equals("int"))
			    	    {
			    		sql+=(extmap.get(str)==null?"":extmap.get(str))+",";
			    	    }else{
			    	    sql+="'"+(extmap.get(str)==null?"":extmap.get(str))+"',";
			    	    }
			    	}
			    }
			    
			    sql=sql.substring(0,sql.length()-1)+")";
			    System.out.println(sql);
			    this.commOper(sql);
			  
			    st.close();
			     
			} catch (SQLException e) {
				e.printStackTrace();
			}
			String str = "";
			if(!reflush)
			 str += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \n";
			 str +=	"<script language=javascript>\n";
			if(alert){
			str+="alert('操作成功');\n";
			}
			if(tzurl.equals(""))
			{
				if(reflush){
					str+="parent.location=parent.location;\n";
				}else{
					str+="window.location=String(window.location).replace(new RegExp('f=f', 'g'), '');";
				}
			}
			else
			{
				str+="location.href='"+tzurl+"';\n";
			}
			
			str+="</script>";
			
			
			PrintWriter wrt = null;
			try {
			wrt = response.getWriter();
			} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			}
			wrt.write(str);
			}
			
			return "";
		}
		
		public void delete(HttpServletRequest request,String tablename)
		{
			
			int i = 0;
			try {
				String did = request.getParameter("did");
				if(did==null)did = request.getParameter("scid");
				if(did!=null){
					if(did.length()>0){
				Statement st = conn.createStatement();
				System.out.println("delete from "+tablename+" where id="+did);
				 st.execute("delete from "+tablename+" where id="+did);
				 st.close();
					}
				}
				 
				   
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}

		
		
		public String getCols(String table)
		{  
			String str = "";
			Connection conn = this.getConn();
			try {
				Statement st = conn.createStatement();
			    ResultSet rs = st.executeQuery("select * from "+table);
			    ResultSetMetaData rsmd = rs.getMetaData();
			    
			    int i = rsmd.getColumnCount(); 
		    	for(int j=2;j<=i;j++)
		    	{
		    	str+=rsmd.getColumnName(j)+",";
		    	}
			    
			}catch (Exception e) {
				e.printStackTrace();
			}
			str = str.substring(0,str.length()-1);
			 
			return str;
		}
		
		
		public String update(HttpServletRequest request,HttpServletResponse response, String tablename,HashMap extmap,boolean alert,boolean reflush,String tzurl)
		{
			if(request.getParameter("f")!=null){
			Enumeration enumeration = request.getParameterNames();
			String names = ",";
			while(enumeration.hasMoreElements())
			{
			names += enumeration.nextElement().toString()+",";
			}
			HashMap typemap = new HashMap();
			ArrayList<String> collist = new ArrayList();
			String sql = "update "+tablename+" set ";
			Connection conn = this.getConn();
			try {
				Statement st = conn.createStatement();
			    ResultSet rs = st.executeQuery("select * from "+tablename);
			    ResultSetMetaData rsmd = rs.getMetaData();
	            int i = rsmd.getColumnCount();
			    	System.out.println(i);
			    	for(int j=1;j<=i;j++)
			    	{
			    	if(rsmd.getColumnName(j).equals("id"))continue;
					if(rsmd.getColumnName(j).equals("ID"))continue;
					if(rsmd.getColumnName(j).equals("Id"))continue;
					if(rsmd.getColumnName(j).equals("iD"))continue;
			    	typemap.put(rsmd.getColumnName(j)+"---", rsmd.getColumnTypeName(j));
			    	collist.add(rsmd.getColumnName(j));
	    	    	if(names.indexOf(","+rsmd.getColumnName(j)+",")>-1)
	    	    	{
	    	    		
	    	    		String[] values = request.getParameterValues(rsmd.getColumnName(j));
			    		String value="";
			    		for(String vstr:values)
			    		{
			    			if(vstr==null)vstr="";
			    			if(vstr.equals("null"))vstr="";
			    			if(vstr.trim().equals(""))continue;
			    			
			    			if(request.getParameter(vstr)!=null&&!"".equals(request.getParameter(vstr))&&request.getParameter("dk-"+rsmd.getColumnName(j)+"-value")!=null)
			    			{
			    				String dkv = request.getParameter(vstr);
			    				String dknamevalue = request.getParameter("dk-"+rsmd.getColumnName(j)+"-value");
			    				vstr+=" - "+dknamevalue+":"+dkv;
			    				System.out.println(vstr);
			    			}
			    			//if(vstr.length()<)
			    			value+=vstr+" ~ ";
			    		}
			    		if(value==null)value="";
		    			if(value.equals("null"))value="";
			    		if(value.length()>0)value=value.substring(0,value.length()-3);
	    	    		
	    	    		if(rsmd.getColumnTypeName(j).equals("int"))
	    	    		{
	    	    		 sql+=rsmd.getColumnName(j)+"="+value+",";
	    	    		}else{
	    	    			 sql+=rsmd.getColumnName(j)+"='"+value+"',";
	    	    		}
	    	    	}else{
	    	    		if(extmap.get(rsmd.getColumnName(j))!=null)
	    	    		{
	    	    			if(rsmd.getColumnTypeName(j).equals("int"))
	        	    		{
	        	    		 sql+=rsmd.getColumnName(j)+"="+extmap.get(rsmd.getColumnName(j))+",";
	        	    		}else{
	        	    			 sql+=rsmd.getColumnName(j)+"='"+extmap.get(rsmd.getColumnName(j))+"',";
	        	    		}
	    	    		}
	    	    	}
			    	}
			    	sql = sql.substring(0,sql.length()-1);
			    	sql+=" where id="+request.getParameter("id");
			       System.out.println(sql);
			    	Statement st1 = conn.createStatement();
			    	st1.execute(sql);
			    	st1.close();
			    rs.close();
			    st.close(); 
			     
			} catch (SQLException e) {
				e.printStackTrace();
			}
			String str = "";
			if(!reflush)
			 str += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" ;
			 str +=	"<script language=javascript>\n";
			if(alert){
			str+="alert('操作成功');\n";
			}
			if(tzurl.equals(""))
			{
				if(reflush){
					str+="parent.location=parent.location;\n";
				}else{
					str+="window.location=String(window.location).replace(new RegExp('f=f', 'g'), '');";
				}
			}
			else
			{
				str+="location.href='"+tzurl+"';\n";
			}
			
			 
			str+="</script>\n";
			
			PrintWriter wrt = null;
			try {
				//request.get
			wrt = response.getWriter();
			} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			}
			wrt.write(str);
			}
	        return "";
		}
		
		
	
		public Connection getConn()
		{
		        try
		        { 
		        	if(conn==null||conn.isClosed()){
						Class.forName("net.sourceforge.jtds.jdbc.Driver");
           conn = DriverManager.getConnection("jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=jspm53178kqglxtsx", "sa", "123456");
		            }}
		        catch(Exception e)
		        {
		            e.printStackTrace();
		        }
		        return conn;
		}
	
	
	public int getInt(String sql)
	{
		int i = 0;
		try {
			Statement st = conn.createStatement();
			ResultSet rs = st.executeQuery(sql);
			if(rs.next())
			{
				i = rs.getInt(1);
			}
			    st.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	
	public double getDouble(String sql)
	{
		double i = 0;
		try {
			Statement st = conn.createStatement();
			ResultSet rs = st.executeQuery(sql);
			if(rs.next())
			{
				i = rs.getDouble(1);
				
			}
			    st.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	public void commOper(String sql)
	{
		System.out.println(sql);
		try {
			Statement st = conn.createStatement();
		    st.execute(sql);
		    st.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void commOperSqls(ArrayList<String> sql)
	{
		
		try {
			conn.setAutoCommit(false);
			for(int i=0;i<sql.size();i++)
			{
			Statement st = conn.createStatement();
			System.out.println(sql.get(i));
		    st.execute(sql.get(i));
		    st.close();
			}
			conn.commit();
		} catch (SQLException e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
			try {
				conn.setAutoCommit(true);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	
	public List<HashMap> select(String sql)
	{ 
		System.out.println(sql);
		List<HashMap> list = new ArrayList();
		try {
			Statement st = conn.createStatement();
		    ResultSet rs = st.executeQuery(sql);
		    ResultSetMetaData rsmd = rs.getMetaData();
           
		    while(rs.next())
		    {
		    	HashMap map = new HashMap();
		    	int i = rsmd.getColumnCount();
		    	for(int j=1;j<=i;j++)
		    	{
		    		if(!rsmd.getColumnName(j).equals("ID"))
		    		{
		    			String str = rs.getString(j)==null?"": rs.getString(j);
		    			if(str.equals("null"))str = "";
		    			map.put(rsmd.getColumnName(j), str);
		    		}
		    		else
		    			map.put("id", rs.getString(j));
		    	}
		    	list.add(map);
		    }
		    rs.close();
		    st.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			
			if(sql.equals("show tables"))
			list = select("select table_name from   INFORMATION_SCHEMA.tables");
			else
				e.printStackTrace();
		}
		return list;
	}
	
	
	public List<List> selectforlist(String sql)
	{
		List<List> list = new ArrayList();
		try {
			Statement st = conn.createStatement();
		    ResultSet rs = st.executeQuery(sql);
		    ResultSetMetaData rsmd = rs.getMetaData();
           
		    while(rs.next())
		    {
		    	List<String> list2 = new ArrayList();
		    	int i = rsmd.getColumnCount();
		    	for(int j=1;j<=i;j++)
		    	{
		    		if(!rsmd.getColumnName(j).equals("ID"))
		    		{
		    			String str = rs.getString(j)==null?"": rs.getString(j);
		    			if(str.equals("null"))str = "";
		    			list2.add( str);
		    		}
		    		else
		    			list2.add(rs.getString(j));
		    	}
		    	list.add(list2);
		    }
		    rs.close();
		    st.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	
	public void close()
	{
		 
	}
	
	/**
	 * 执行一条查询sql,以 List<hashmap> 的形式返回查询的记录,记录条数,和从第几条开始,由参数决定,主要用于翻页
	 * pageno 页码  rowsize 每页的条数
	 */
	public List<HashMap> select(String sql, int pageno, int rowsize) {
		List<HashMap> list=new ArrayList<HashMap>();
		List<HashMap> mlist=new ArrayList<HashMap>();
		try{
			list=this.select(sql);
			int min = (pageno-1)*rowsize;
			int max = pageno*rowsize;
			
			for(int i=0;i<list.size();i++)
			{
				
				if(!(i<min||i>(max-1)))
				{
				mlist.add(list.get(i));
				}
			}
		}catch(RuntimeException re){
			re.printStackTrace();
			throw re;
		}
		
		
		return mlist;
	}
	

	
	
	public static void main(String[] args) { 
	}
}

 

 

 

 

 

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到