Select.java
上传用户:sxwtmm
上传日期:2022-08-11
资源大小:2183k
文件大小:5k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2.  * Created on 2004-9-25
  3.  *
  4.  * To change the template for this generated file go to
  5.  * Window>Preferences>Java>Code Generation>Code and Comments
  6.  */
  7. package com.em;
  8. import oa.sys.*;
  9. import oa.data.*;
  10. import java.io.*;
  11. import java.sql.*;
  12. import java.util.*;
  13. import javax.servlet.*;
  14. import javax.servlet.http.*;
  15. /**
  16.  ****************************************************
  17.  *类名称: Select<br>
  18.  *类功能: 查询部门、职位、员工状态信息<br>
  19.  *创建: 白伟明 2004年9月28日<br>
  20.  ****************************************************
  21.  * To change the template for this generated type comment go to
  22.  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  23.  */
  24. public class Select extends HttpServlet{
  25. private RequestDispatcher dispatcher=null;
  26. private HttpSession session=null;
  27. private Statement stmt=null;
  28. private ResultSet rs=null;
  29. private Statement stmt1=null;
  30. private ResultSet rs1=null;
  31. private String select,column,name,birthday,dep,job,state,learn,post,tel,addr,sql;
  32. private PrintWriter out=null;
  33. private int id,sex,deid,jobid,stateid;
  34. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  35. request.setCharacterEncoding("gb2312");
  36. response.setContentType("text/html; charset=gb2312");
  37. session=request.getSession();
  38. out=response.getWriter();
  39. Db db=new Db();
  40. Str str=new Str();
  41. Collection coll=new ArrayList();
  42. column=(String)request.getParameter("column");
  43. select=(String)request.getParameter("sele");
  44. select=str.inStr(select).trim();
  45. //调整性别系数
  46. if(select.equals("男")){
  47. select="1";
  48. }
  49. if(select.equals("女")){
  50. select="0";
  51. }
  52. //利用部门、职位、状态各自名称分别取出id号再进行查询
  53. if(column.equals("departmentid")){
  54. try{
  55. stmt=db.getStmtread();
  56. rs=stmt.executeQuery("SELECT departmentid FROM department WHERE name LIKE '%"+select+"%'");
  57. if(rs.next()){
  58. select=new Integer(rs.getInt(1)).toString();
  59. }
  60. }catch(Exception e){
  61. e.printStackTrace();
  62. }finally{
  63. db.close();
  64. }
  65. }
  66. if(column.equals("jobid")){
  67. try{
  68. stmt=db.getStmtread();
  69. rs=stmt.executeQuery("SELECT jobid FROM job WHERE name LIKE '%"+select+"%'");
  70. if(rs.next()){
  71. select=new Integer(rs.getInt(1)).toString();
  72. }
  73. }catch(Exception e){
  74. e.printStackTrace();
  75. }finally{
  76. db.close();
  77. }
  78. }
  79. if(column.equals("stateid")){
  80. try{
  81. stmt=db.getStmtread();
  82. rs=stmt.executeQuery("SELECT stateid FROM emstate WHERE name LIKE '%"+select+"%'");
  83. if(rs.next()){
  84. select=new Integer(rs.getInt(1)).toString();
  85. }
  86. }catch(Exception e){
  87. e.printStackTrace();
  88. }finally{
  89. db.close();
  90. }
  91. }
  92. //查询员工信息
  93. sql="SELECT * FROM eminfo WHERE "+column+" LIKE '%"+select+"%'";
  94. if(column.equals("birthday")){
  95. sql="SELECT * FROM eminfo WHERE "+column+" = '"+select+"'";
  96. }
  97. try{
  98. stmt=db.getStmtread();
  99. rs=stmt.executeQuery(sql);
  100. if(rs.next()){
  101. rs.beforeFirst();
  102. while(rs.next()){
  103. id=rs.getInt(1);
  104. name=rs.getString(2);
  105. sex=rs.getInt(3);
  106. birthday=rs.getString(4);
  107. learn=rs.getString(5);
  108. post=rs.getString(6);
  109. deid=rs.getInt(7);
  110. jobid=rs.getInt(8);
  111. tel=rs.getString(9);
  112. addr=rs.getString(10);
  113. stateid=rs.getInt(11);
  114. dep=db.IdtoDo("Name","department WHERE departmentid="+deid);
  115. job=db.IdtoDo("Name","job WHERE jobid="+jobid);
  116. state=db.IdtoDo("Name","emstate WHERE stateid="+stateid);
  117. //字符转换
  118. name=str.outStr(name);
  119. birthday=birthday.substring(0,10);
  120. dep=str.outStr(dep);
  121. job=str.outStr(job);
  122. state=str.outStr(state);
  123. learn=str.outStr(learn);
  124. post=str.outStr(post);
  125. tel=str.outStr(tel);
  126. addr=str.outStr(addr);
  127. Eminfo eminfo=new Eminfo();
  128. eminfo.setId(id);
  129. eminfo.setName(name);
  130. eminfo.setSex(sex);
  131. eminfo.setBirthday(birthday);
  132. eminfo.setLearn(learn);
  133. eminfo.setPost(post);
  134. eminfo.setDepartment(dep);
  135. eminfo.setJob(job);
  136. eminfo.setTel(tel);
  137. eminfo.setAddr(addr);
  138. eminfo.setState(state);
  139. coll.add(eminfo);
  140. }//while
  141. request.setAttribute("msg",coll);
  142. }else{
  143. request.setAttribute("msg2","没有您要的查询结果");
  144. }
  145. }catch(Exception e){
  146. e.printStackTrace();
  147. }finally{
  148. db.close();
  149. dispatcher=request.getRequestDispatcher("select.jsp");
  150. dispatcher.forward(request,response);
  151. }
  152. }
  153. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  154. doPost(request,response);
  155. }
  156. }