前文:https://www.cnblogs.com/Arisf/p/14095002.html

在之前图书管理系统上做了改进优化

图书管理系统v2

首先是项目结构:

1.数据库的连接:

  1. 1 package db;
  2. 2
  3. 3 import java.sql.Connection;
  4. 4 import java.sql.DriverManager;
  5. 5 import java.sql.PreparedStatement;
  6. 6 import java.sql.ResultSet;
  7. 7 import java.sql.SQLException;
  8. 8 import java.sql.Statement;
  9. 9
  10. 10 public class DBUtil {
  11. 11 private static String url = "jdbc:mysql://localhost:3306/book system?&useSSL=false&serverTimezone=UTC";
  12. 12 private static String user = "root";//用户名一般默认是root
  13. 13 private static String password = "";//自己的密码
  14. 14 private static String jdbcName="com.mysql.cj.jdbc.Driver";
  15. 15 private Connection con=null;
  16. 16 public static Connection getConnection() {
  17. 17 Connection con=null;
  18. 18 try {
  19. 19 Class.forName(jdbcName);
  20. 20 con=DriverManager.getConnection(url, user, password);
  21. 21 //System.out.println("数据库连接成功");
  22. 22 } catch (Exception e) {
  23. 23 // TODO Auto-generated catch block
  24. 24 //System.out.println("数据库连接失败");
  25. 25 e.printStackTrace();
  26. 26 }
  27. 27 try {
  28. 28 con = DriverManager.getConnection(url,user,password);
  29. 29 System.out.println("数据库连接成功");
  30. 30
  31. 31
  32. 32 } catch (SQLException e) {
  33. 33 // TODO: handle exception
  34. 34 e.printStackTrace();
  35. 35 }
  36. 36 return con;
  37. 37 }
  38. 38 public static void main(String[] args)throws SQLException {
  39. 39 Connection conn = getConnection();
  40. 40 PreparedStatement pstmt = null;
  41. 41 ResultSet rs = null;
  42. 42 String sql ="select * from user_information";
  43. 43 pstmt = conn.prepareStatement(sql);
  44. 44 rs = pstmt.executeQuery();
  45. 45 System.out.println(getConnection());
  46. 46 while(rs.next()){
  47. 47 System.out.println("数据表连接成功");
  48. 48 }
  49. 49
  50. 50 }
  51. 51
  52. 52 public static void close(Connection con) {
  53. 53 if(con!=null)
  54. 54 try {
  55. 55 con.close();
  56. 56 } catch (SQLException e) {
  57. 57 // TODO Auto-generated catch block
  58. 58 e.printStackTrace();
  59. 59 }
  60. 60
  61. 61 }
  62. 62 public static void close(Statement state, Connection conn) {
  63. 63 if(state!=null) {
  64. 64 try {
  65. 65 state.close();
  66. 66 } catch (SQLException e) {
  67. 67 e.printStackTrace();
  68. 68 }
  69. 69 }
  70. 70 if(conn!=null) {
  71. 71 try {
  72. 72 conn.close();
  73. 73 } catch (SQLException e) {
  74. 74 e.printStackTrace();
  75. 75 }
  76. 76 }
  77. 77 }
  78. 78
  79. 79 public static void close(ResultSet rs, Statement state, Connection conn) {
  80. 80 if(rs!=null) {
  81. 81 try {
  82. 82 rs.close();
  83. 83 } catch (SQLException e) {
  84. 84 e.printStackTrace();
  85. 85 }
  86. 86 }
  87. 87 if(state!=null) {
  88. 88 try {
  89. 89 state.close();
  90. 90 } catch (SQLException e) {
  91. 91 e.printStackTrace();
  92. 92 }
  93. 93 }
  94. 94 if(conn!=null) {
  95. 95 try {
  96. 96 conn.close();
  97. 97 } catch (SQLException e) {
  98. 98 e.printStackTrace();
  99. 99 }
  100. 100 }
  101. 101 }
  102. 102
  103. 103 }

2.实体类(3个——图书表,借书表,用户表)

  1. 1 package bean;
  2. 2
  3. 3 public class Bean_book {
  4. 4 private int id;
  5. 5 private String name;
  6. 6 private String writer;
  7. 7 private String press;
  8. 8 private int num;
  9. 9
  10. 10
  11. 11 public int getId() {
  12. 12 return id;
  13. 13 }
  14. 14 public void setId(int id) {
  15. 15 this.id = id;
  16. 16 }
  17. 17
  18. 18 public String getName() {
  19. 19 return name;
  20. 20 }
  21. 21 public void setName(String name) {
  22. 22 this.name = name;
  23. 23 }
  24. 24
  25. 25 public String getWriter() {
  26. 26 return writer;
  27. 27 }
  28. 28 public void setWriter(String writer) {
  29. 29 this.writer = writer;
  30. 30 }
  31. 31
  32. 32 public String getPress() {
  33. 33 return press;
  34. 34 }
  35. 35 public void setPress(String press) {
  36. 36 this.press = press;
  37. 37 }
  38. 38
  39. 39 public int getNum() {
  40. 40 return num;
  41. 41 }
  42. 42 public void setNum(int num) {
  43. 43 this.num = num;
  44. 44 }
  45. 45
  46. 46
  47. 47 public Bean_book(int id, String name, String writer, String press,int num) {
  48. 48 this.id = id;
  49. 49 this.name = name;
  50. 50 this.writer = writer;
  51. 51 this.press = press;
  52. 52 this.num = num;
  53. 53 }
  54. 54
  55. 55
  56. 56
  57. 57 public String toString() {
  58. 58 return "Book{" +
  59. 59 "id=" + id +
  60. 60 ", name='" + name + '\'' +
  61. 61 ", writer='" + writer + '\'' +
  62. 62 ", press='" + press + '\'' +
  63. 63 ", num=" + num +
  64. 64 '}';
  65. 65 }
  66. 66
  67. 67
  68. 68 }
  1. 1 package bean;
  2. 2
  3. 3
  4. 4 public class Bean_borrowing {
  5. 5 private int id;
  6. 6 private String name;
  7. 7 private String writer;
  8. 8 private String press;
  9. 9 private String date;
  10. 10 private int borrower;
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15 public int getId() {
  16. 16 return id;
  17. 17 }
  18. 18 public void setId(int id) {
  19. 19 this.id = id;
  20. 20 }
  21. 21
  22. 22 public String getName() {
  23. 23 return name;
  24. 24 }
  25. 25 public void setName(String name) {
  26. 26 this.name = name;
  27. 27 }
  28. 28
  29. 29 public String getWriter() {
  30. 30 return writer;
  31. 31 }
  32. 32 public void setWriter(String writer) {
  33. 33 this.writer = writer;
  34. 34 }
  35. 35
  36. 36 public String getPress() {
  37. 37 return press;
  38. 38 }
  39. 39 public void setPress(String press) {
  40. 40 this.press = press;
  41. 41 }
  42. 42
  43. 43 public String getDate() {
  44. 44 return date;
  45. 45 }
  46. 46 public void setDate(String date) {
  47. 47 this.date = date;
  48. 48 }
  49. 49 public int getBorrower() {
  50. 50 return borrower;
  51. 51 }
  52. 52 public void setBorrower(int borrower) {
  53. 53 this.borrower = borrower;
  54. 54 }
  55. 55
  56. 56 public Bean_borrowing(int id, String name, String writer, String press,String date,int borrower) {
  57. 57 this.id = id;
  58. 58 this.name = name;
  59. 59 this.writer = writer;
  60. 60 this.press = press;
  61. 61 this.date = date;
  62. 62 this.borrower=borrower;
  63. 63 }
  64. 64
  65. 65 public String toString() {
  66. 66 return "Borrowing{" +
  67. 67 "id=" + id +
  68. 68 ", name='" + name + '\'' +
  69. 69 ", writer='" + writer + '\'' +
  70. 70 ", press='" + press + '\'' +
  71. 71 ", date='" + date + '\'' +
  72. 72 ", borrower=" + borrower +
  73. 73 '}';
  74. 74 }
  75. 75
  76. 76 }
  1. 1 package bean;
  2. 2
  3. 3 public class Bean_user {
  4. 4
  5. 5 private int uid;
  6. 6 private String name;
  7. 7 private String sex;
  8. 8 private String college;
  9. 9 private String password;
  10. 10 private String identity;
  11. 11
  12. 12
  13. 13 public int getUid() {
  14. 14 return uid;
  15. 15 }
  16. 16 public void setUid(int uid) {
  17. 17 this.uid = uid;
  18. 18 }
  19. 19
  20. 20 public String getName() {
  21. 21 return name;
  22. 22 }
  23. 23 public void setName(String name) {
  24. 24 this.name = name;
  25. 25 }
  26. 26
  27. 27 public String getSex() {
  28. 28 return sex;
  29. 29 }
  30. 30 public void setSex(String sex) {
  31. 31 this.sex = sex;
  32. 32 }
  33. 33
  34. 34 public String getCollege() {
  35. 35 return college;
  36. 36 }
  37. 37 public void setCollege(String college) {
  38. 38 this.college = college;
  39. 39 }
  40. 40
  41. 41 public String getPassword() {
  42. 42 return password;
  43. 43 }
  44. 44 public void setPassword(String password) {
  45. 45 this.password = password;
  46. 46 }
  47. 47
  48. 48 public String getIdentity() {
  49. 49 return identity;
  50. 50 }
  51. 51 public void setIdentity(String identity) {
  52. 52 this.identity = identity;
  53. 53 }
  54. 54
  55. 55 public Bean_user(int uid, String name, String sex, String college,String password,String identity) {
  56. 56 this.uid = uid;
  57. 57 this.name = name;
  58. 58 this.sex = sex;
  59. 59 this.college = college;
  60. 60 this.password = password;
  61. 61 this.identity = identity;
  62. 62 }
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67 public String toString() {
  68. 68 return "User{" +
  69. 69 "uid=" + uid +
  70. 70 ", name='" + name + '\'' +
  71. 71 ", sex='" + sex + '\'' +
  72. 72 ", college='" + college + '\'' +
  73. 73 ", password='" + password + '\'' +
  74. 74 ", identity=" + identity +
  75. 75 '}';
  76. 76 }
  77. 77
  78. 78 }

3.Dao

  1. 1 package dao;
  2. 2
  3. 3 import java.sql.Connection;
  4. 4 import java.sql.PreparedStatement;
  5. 5 import java.sql.ResultSet;
  6. 6 import java.sql.SQLException;
  7. 7 import java.sql.Statement;
  8. 8 import java.text.SimpleDateFormat;
  9. 9 import java.util.ArrayList;
  10. 10 import java.util.Date;
  11. 11 import java.util.List;
  12. 12
  13. 13 import bean.Bean_user;
  14. 14 import bean.Bean_book;
  15. 15 import bean.Bean_borrowing;
  16. 16 import db.DBUtil;
  17. 17
  18. 18 public class Dao {
  19. 19 //dao层
  20. 20 private DBUtil dbutil=new DBUtil();
  21. 21
  22. 22
  23. 23 public Dao() {
  24. 24 // TODO Auto-generated constructor stub
  25. 25 }
  26. 26 public boolean insert_user(Bean_user bean) {//插入读者数据的方法
  27. 27 boolean f=false;
  28. 28 String sql="insert into user_information(uid,name,sex,college,password,identity) values('"+bean.getUid()+"','"+bean.getName()+"','"+bean.getSex()+"','"+bean.getCollege()+"','"+bean.getPassword()+"','"+bean.getIdentity()+"')";
  29. 29 Connection conn=DBUtil.getConnection();//数据库连接,加载驱动
  30. 30 Statement state=null;
  31. 31 try
  32. 32 {
  33. 33 state=conn.createStatement();//实例化Statement对象,方便对sql语句进行操作
  34. 34 System.out.println(conn);
  35. 35 state.executeUpdate(sql);
  36. 36 f=true;
  37. 37 //执行数据库更新操作用于执行INSERT、UPDATE或DELETE语句以及SQLDDL(数据定义语言)语句,
  38. 38 //例如CREATETABLE和DROPTABLE,(创建表和删除表)
  39. 39 }catch(Exception e)//当try语句中s出现异常时,会执行catch中的语句
  40. 40 {
  41. 41 e.printStackTrace();//捕获异常的语句
  42. 42 }
  43. 43 finally //finally作为异常处理的一部分,它只能用在try/catch语句中,并且附带一个语句块,表示这段语句最终一定会被执行(不管有没有抛出异常),经常被用在需要释放资源的情况下。
  44. 44 {
  45. 45 DBUtil.close(conn);
  46. 46 }
  47. 47 return f;
  48. 48 }
  49. 49
  50. 50 public boolean insert_book(Bean_book bean) {//插入图书数据的方法
  51. 51 boolean f=false;
  52. 52 String sql="insert into book_information(id,name,writer,press,num) values('"+bean.getId()+"','"+bean.getName()+"','"+bean.getWriter()+"','"+bean.getPress()+"','"+bean.getNum()+"')";
  53. 53 Connection conn=DBUtil.getConnection();//数据库连接,加载驱动
  54. 54 Statement state=null;
  55. 55 try
  56. 56 {
  57. 57 state=conn.createStatement();//实例化Statement对象,方便对sql语句进行操作
  58. 58 System.out.println(conn);
  59. 59 state.executeUpdate(sql);
  60. 60 f=true;
  61. 61 //执行数据库更新操作用于执行INSERT、UPDATE或DELETE语句以及SQLDDL(数据定义语言)语句,
  62. 62 //例如CREATETABLE和DROPTABLE,(创建表和删除表)
  63. 63 }catch(Exception e)//当try语句中s出现异常时,会执行catch中的语句
  64. 64 {
  65. 65 e.printStackTrace();//捕获异常的语句
  66. 66 }
  67. 67 finally //finally作为异常处理的一部分,它只能用在try/catch语句中,并且附带一个语句块,表示这段语句最终一定会被执行(不管有没有抛出异常),经常被用在需要释放资源的情况下。
  68. 68 {
  69. 69 DBUtil.close(conn);
  70. 70 }
  71. 71 return f;
  72. 72 }
  73. 73
  74. 74 public boolean insert_borrowing(Bean_borrowing bean) {//插入图书数据的方法
  75. 75 boolean f=false;
  76. 76 String sql="insert into borrowing_information(id,name,writer,press,date,borrower) values('"+bean.getId()+"','"+bean.getName()+"','"+bean.getWriter()+"','"+bean.getPress()+"','"+bean.getDate()+"','"+bean.getBorrower()+"')";
  77. 77 Connection conn=DBUtil.getConnection();//数据库连接,加载驱动
  78. 78 Statement state=null;
  79. 79 try
  80. 80 {
  81. 81 state=conn.createStatement();//实例化Statement对象,方便对sql语句进行操作
  82. 82 System.out.println(conn);
  83. 83 state.executeUpdate(sql);
  84. 84 f=true;
  85. 85 //执行数据库更新操作用于执行INSERT、UPDATE或DELETE语句以及SQLDDL(数据定义语言)语句,
  86. 86 //例如CREATETABLE和DROPTABLE,(创建表和删除表)
  87. 87 }catch(Exception e)//当try语句中s出现异常时,会执行catch中的语句
  88. 88 {
  89. 89 e.printStackTrace();//捕获异常的语句
  90. 90 }
  91. 91 finally //finally作为异常处理的一部分,它只能用在try/catch语句中,并且附带一个语句块,表示这段语句最终一定会被执行(不管有没有抛出异常),经常被用在需要释放资源的情况下。
  92. 92 {
  93. 93 DBUtil.close(conn);
  94. 94 }
  95. 95 return f;
  96. 96 }
  97. 97
  98. 98
  99. 99
  100. 100 public List<Bean_book> list(){//查询所有方法
  101. 101 String sql="select * from book_information order by id ASC";
  102. 102 Connection conn=DBUtil.getConnection();
  103. 103 Statement st=null;
  104. 104 List<Bean_book> list=new ArrayList<>();
  105. 105 ResultSet rs=null;
  106. 106 Bean_book bean=null;
  107. 107 try {
  108. 108 st=conn.createStatement();
  109. 109 st.executeQuery(sql);
  110. 110 rs=st.executeQuery(sql);
  111. 111 while(rs.next()) {
  112. 112 int id=rs.getInt("id");
  113. 113 String name = rs.getString("name");
  114. 114 String writer = rs.getString("writer");
  115. 115 String press = rs.getString("press");
  116. 116 int num=rs.getInt("num");
  117. 117 bean=new Bean_book(id,name,writer,press,num);
  118. 118 list.add(bean);
  119. 119 }
  120. 120 } catch (SQLException e) {
  121. 121 // TODO Auto-generated catch block
  122. 122 e.printStackTrace();
  123. 123 }
  124. 124 finally {
  125. 125 DBUtil.close(rs, st, conn);
  126. 126 }
  127. 127 return list;
  128. 128 }
  129. 129
  130. 130 public List<Bean_borrowing> borrower(int uid){//查询所有方法
  131. 131 String sql="select * from borrowing_information where borrower='"+uid+"' order by date ASC";
  132. 132 Connection conn=DBUtil.getConnection();
  133. 133 Statement st=null;
  134. 134 List<Bean_borrowing> borrower=new ArrayList<>();
  135. 135 ResultSet rs=null;
  136. 136 Bean_borrowing bean=null;
  137. 137 try {
  138. 138 st=conn.createStatement();
  139. 139 st.executeQuery(sql);
  140. 140 rs=st.executeQuery(sql);
  141. 141 while(rs.next()) {
  142. 142 int id=rs.getInt("id");
  143. 143 String name = rs.getString("name");
  144. 144 String writer = rs.getString("writer");
  145. 145 String press = rs.getString("press");
  146. 146 String date = rs.getString("date");
  147. 147 bean=new Bean_borrowing(id,name,writer,press,date,uid);
  148. 148 borrower.add(bean);
  149. 149 }
  150. 150 } catch (SQLException e) {
  151. 151 // TODO Auto-generated catch block
  152. 152 e.printStackTrace();
  153. 153 }
  154. 154 finally {
  155. 155 DBUtil.close(rs, st, conn);
  156. 156 }
  157. 157 return borrower;
  158. 158 }
  159. 159
  160. 160 public List<Bean_borrowing> list_overtime(){//查询过期书
  161. 161
  162. 162 Date date=new Date();
  163. 163 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  164. 164 String now=sdf.format(date);
  165. 165
  166. 166 String sql="select * from borrowing_information where date < '"+now+"' order by date ASC";
  167. 167 Connection conn=DBUtil.getConnection();
  168. 168 Statement st=null;
  169. 169 List<Bean_borrowing> list_overtime=new ArrayList<>();
  170. 170 ResultSet rs=null;
  171. 171 Bean_borrowing bean=null;
  172. 172 try {
  173. 173 st=conn.createStatement();
  174. 174 st.executeQuery(sql);
  175. 175 rs=st.executeQuery(sql);
  176. 176 while(rs.next()) {
  177. 177 int id=rs.getInt("id");
  178. 178 int borrower=rs.getInt("borrower");
  179. 179 String name = rs.getString("name");
  180. 180 String writer = rs.getString("writer");
  181. 181 String press = rs.getString("press");
  182. 182 String date1 = rs.getString("date");
  183. 183 bean=new Bean_borrowing(id,name,writer,press,date1,borrower);
  184. 184 list_overtime.add(bean);
  185. 185 }
  186. 186 } catch (SQLException e) {
  187. 187 // TODO Auto-generated catch block
  188. 188 e.printStackTrace();
  189. 189 }
  190. 190 finally {
  191. 191 DBUtil.close(rs, st, conn);
  192. 192 }
  193. 193 return list_overtime;
  194. 194 }
  195. 195
  196. 196
  197. 197 public List<Bean_book> searchByName(String str) throws SQLException{//查询条件方法
  198. 198 String sql="select * from book_information where(name like '%"+str+"%')";
  199. 199 Connection conn=DBUtil.getConnection();
  200. 200 Statement st=null;
  201. 201 PreparedStatement pt = conn.prepareStatement(sql);
  202. 202 List<Bean_book> search=new ArrayList<>();
  203. 203 ResultSet rs=null;
  204. 204 Bean_book bean=null;
  205. 205 try {
  206. 206 pt=conn.prepareStatement(sql);
  207. 207 rs=pt.executeQuery();
  208. 208 while(rs.next()) {
  209. 209 int id=rs.getInt("id");
  210. 210 String name = rs.getString("name");
  211. 211 String writer = rs.getString("writer");
  212. 212 String press = rs.getString("press");
  213. 213 int num=rs.getInt("num");
  214. 214 bean=new Bean_book(id,name,writer,press,num);
  215. 215 search.add(bean);
  216. 216 }
  217. 217 } catch (SQLException e) {
  218. 218 // TODO Auto-generated catch block
  219. 219 e.printStackTrace();
  220. 220 }
  221. 221 finally {
  222. 222 DBUtil.close(rs, st, conn);
  223. 223 }
  224. 224 return search;
  225. 225 }
  226. 226
  227. 227 public List<Bean_book> searchByWriter(String str) throws SQLException{//查询条件方法
  228. 228 String sql="select * from book_information where(writer like '%"+str+"%')";
  229. 229 Connection conn=DBUtil.getConnection();
  230. 230 Statement st=null;
  231. 231 PreparedStatement pt = conn.prepareStatement(sql);
  232. 232 List<Bean_book> search=new ArrayList<>();
  233. 233 ResultSet rs=null;
  234. 234 Bean_book bean=null;
  235. 235 try {
  236. 236 pt=conn.prepareStatement(sql);
  237. 237 rs=pt.executeQuery();
  238. 238 while(rs.next()) {
  239. 239 int id=rs.getInt("id");
  240. 240 String name = rs.getString("name");
  241. 241 String writer = rs.getString("writer");
  242. 242 String press=rs.getString("press");
  243. 243 int num=rs.getInt("num");
  244. 244 bean=new Bean_book(id,name,writer,press,num);
  245. 245 search.add(bean);
  246. 246 }
  247. 247 } catch (SQLException e) {
  248. 248 // TODO Auto-generated catch block
  249. 249 e.printStackTrace();
  250. 250 }
  251. 251 finally {
  252. 252 DBUtil.close(rs, st, conn);
  253. 253 }
  254. 254 return search;
  255. 255 }
  256. 256
  257. 257 public boolean update(Bean_book bean) {//更新自减方法
  258. 258 String sql="update book_information set num='"+bean.getNum()+"',name='"+bean.getName()+"',writer='"+bean.getWriter()+"',press='"+bean.getPress()+"'where id='"+bean.getId()+"'";
  259. 259 Connection conn=DBUtil.getConnection();
  260. 260 boolean f=false;
  261. 261 Statement st=null;
  262. 262 try {
  263. 263 st=conn.createStatement();
  264. 264 st.executeUpdate(sql);
  265. 265 f=true;
  266. 266 } catch (SQLException e) {
  267. 267 // TODO Auto-generated catch block
  268. 268 e.printStackTrace();
  269. 269 }
  270. 270 return f;
  271. 271 }
  272. 272
  273. 273 public boolean delete_book(int id ) {//删除方法
  274. 274 String sql="delete from book_information where id='"+id+"'";
  275. 275 boolean f=false;
  276. 276 Connection conn =DBUtil.getConnection();
  277. 277 Statement st=null;
  278. 278 try {
  279. 279 st=conn.createStatement();
  280. 280 st.executeUpdate(sql);
  281. 281 f=true;
  282. 282 } catch (SQLException e) {
  283. 283 // TODO Auto-generated catch block
  284. 284 e.printStackTrace();
  285. 285 }
  286. 286 finally{
  287. 287 DBUtil.close(st, conn);
  288. 288 }
  289. 289 return f;
  290. 290 }
  291. 291
  292. 292 public boolean return_book(int id,int uid ) {//删除方法
  293. 293 String sql="delete from borrowing_information where id='"+id+"' and borrower='"+uid+"'";
  294. 294 boolean f=false;
  295. 295 Connection conn =DBUtil.getConnection();
  296. 296 Statement st=null;
  297. 297 try {
  298. 298 st=conn.createStatement();
  299. 299 st.executeUpdate(sql);
  300. 300 f=true;
  301. 301 } catch (SQLException e) {
  302. 302 // TODO Auto-generated catch block
  303. 303 e.printStackTrace();
  304. 304 }
  305. 305 finally{
  306. 306 DBUtil.close(st, conn);
  307. 307 }
  308. 308 return f;
  309. 309 }
  310. 310
  311. 311 }

4.Servlet

  1. 1 package servlet;
  2. 2
  3. 3
  4. 4 import java.io.IOException;
  5. 5 import java.sql.Connection;
  6. 6
  7. 7 import java.sql.DriverManager;
  8. 8 import java.sql.PreparedStatement;
  9. 9 import java.sql.ResultSet;
  10. 10 import java.text.SimpleDateFormat;
  11. 11 import java.util.Date;
  12. 12
  13. 13 import javax.servlet.ServletException;
  14. 14 import javax.servlet.annotation.WebServlet;
  15. 15 import javax.servlet.http.HttpServlet;
  16. 16 import javax.servlet.http.HttpServletRequest;
  17. 17 import javax.servlet.http.HttpServletResponse;
  18. 18
  19. 19
  20. 20
  21. 21 /**
  22. 22 * Servlet implementation class UserServlet
  23. 23 */
  24. 24 @WebServlet("/LoginServlet")
  25. 25 public class LoginServlet extends HttpServlet {
  26. 26 private static final long serialVersionUID = 1L;
  27. 27
  28. 28 /**
  29. 29 * @see HttpServlet#HttpServlet()
  30. 30 */
  31. 31 public LoginServlet() {
  32. 32 super();
  33. 33 // TODO Auto-generated constructor stub
  34. 34 }
  35. 35
  36. 36 /**
  37. 37 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  38. 38 */
  39. 39 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  40. 40 // TODO Auto-generated method stub
  41. 41 response.getWriter().append("Served at: ").append(request.getContextPath());
  42. 42 }
  43. 43
  44. 44 /**
  45. 45 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  46. 46 */
  47. 47 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  48. 48 // TODO Auto-generated method stub
  49. 49 request.setCharacterEncoding("UTF-8");
  50. 50 response.setCharacterEncoding("UTF-8");
  51. 51 int uid=Integer.parseInt(request.getParameter("uid"));
  52. 52 String pass=String.valueOf(request.getParameter("password"));
  53. 53 String identity=String.valueOf(request.getParameter("identity"));
  54. 54 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  55. 55 String date=sdf.format(new Date());
  56. 56 try {
  57. 57 Class.forName("com.mysql.cj.jdbc.Driver");
  58. 58 String url="jdbc:mysql://localhost:3306/book system?&useSSL=false&serverTimezone=UTC";
  59. 59 String username="root";
  60. 60 String password="whyjlbcdy2001";
  61. 61 Connection conn=DriverManager.getConnection(url,username,password);
  62. 62
  63. 63 String sql="select * from user_information where uid='"+uid+"'and password='"+pass+"'and identity='"+identity+"'";
  64. 64
  65. 65 PreparedStatement ps=conn.prepareStatement(sql);
  66. 66 ResultSet rs=ps.executeQuery();
  67. 67 if(rs.next()) {
  68. 68 System.out.println(date+" "+uid+" "+"login"+""+identity);
  69. 69 System.out.println();
  70. 70 request.setAttribute("uid", uid);
  71. 71 if(identity.equals("读者")){
  72. 72 request.getRequestDispatcher("user_index.jsp").forward(request,response);
  73. 73 }
  74. 74 if(identity.equals("管理员")){
  75. 75 request.getRequestDispatcher("admin_index.jsp").forward(request,response);
  76. 76 }
  77. 77 }else{
  78. 78 request.setAttribute("message", "用户名或密码错误");
  79. 79 request.getRequestDispatcher("login.jsp").forward(request,response);
  80. 80 }
  81. 81 }catch(Exception e) {
  82. 82 e.printStackTrace();
  83. 83 }finally{
  84. 84
  85. 85 }
  86. 86 }
  87. 87
  88. 88 }
  1. 1 package servlet;
  2. 2
  3. 3 import java.io.IOException;
  4. 4 import java.sql.SQLException;
  5. 5 import java.util.List;
  6. 6
  7. 7 import javax.servlet.ServletException;
  8. 8 import javax.servlet.annotation.WebServlet;
  9. 9 import javax.servlet.http.HttpServlet;
  10. 10 import javax.servlet.http.HttpServletRequest;
  11. 11 import javax.servlet.http.HttpServletResponse;
  12. 12
  13. 13 import bean.Bean_book;
  14. 14 import dao.Dao;
  15. 15
  16. 16 /**
  17. 17 * Servlet implementation class searchServlet_admin
  18. 18 */
  19. 19 @WebServlet("/searchServlet_admin")
  20. 20 public class SearchServlet_admin extends HttpServlet {
  21. 21 private static final long serialVersionUID = 1L;
  22. 22
  23. 23 /**
  24. 24 * @see HttpServlet#HttpServlet()
  25. 25 */
  26. 26 public SearchServlet_admin() {
  27. 27 super();
  28. 28 // TODO Auto-generated constructor stub
  29. 29 }
  30. 30
  31. 31 /**
  32. 32 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  33. 33 */
  34. 34 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  35. 35 //response.getWriter().append("Served at: ").append(request.getContextPath());
  36. 36 request.setCharacterEncoding("utf-8");
  37. 37 response.setCharacterEncoding("utf-8");
  38. 38 String cxfs=request.getParameter("cxfs");
  39. 39 System.out.print(cxfs);
  40. 40 String str=request.getParameter("value");
  41. 41 Dao dao=new Dao();
  42. 42 List<Bean_book> list = null;
  43. 43 try {
  44. 44 if("1".equals(cxfs)){
  45. 45 list=dao.searchByName(str);
  46. 46 }
  47. 47 if("2".equals(cxfs)){
  48. 48 list=dao.searchByWriter(str);
  49. 49 }
  50. 50 }catch (SQLException e) {
  51. 51 // TODO 自动生成的 catch 块
  52. 52 e.printStackTrace();
  53. 53 }
  54. 54 request.setAttribute("list", list);
  55. 55 request.getRequestDispatcher("delete book.jsp").forward(request,response);
  56. 56 System.out.print(list.size());
  57. 57 }
  58. 58
  59. 59 /**
  60. 60 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  61. 61 */
  62. 62 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  63. 63 // TODO Auto-generated method stub
  64. 64 doGet(request, response);
  65. 65 }
  66. 66
  67. 67 }
  1. 1 package servlet;
  2. 2
  3. 3 import java.io.IOException;
  4. 4 import java.sql.SQLException;
  5. 5 import java.util.List;
  6. 6
  7. 7 import javax.servlet.ServletException;
  8. 8 import javax.servlet.annotation.WebServlet;
  9. 9 import javax.servlet.http.HttpServlet;
  10. 10 import javax.servlet.http.HttpServletRequest;
  11. 11 import javax.servlet.http.HttpServletResponse;
  12. 12
  13. 13 import bean.Bean_book;
  14. 14 import dao.Dao;
  15. 15
  16. 16 /**
  17. 17 * Servlet implementation class searchServlet
  18. 18 */
  19. 19 @WebServlet("/SearchServlet")
  20. 20 public class SearchServlet extends HttpServlet {
  21. 21 private static final long serialVersionUID = 1L;
  22. 22
  23. 23 /**
  24. 24 * @see HttpServlet#HttpServlet()
  25. 25 */
  26. 26 public SearchServlet() {
  27. 27 super();
  28. 28 // TODO Auto-generated constructor stub
  29. 29 }
  30. 30
  31. 31 /**
  32. 32 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  33. 33 */
  34. 34 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  35. 35 // TODO Auto-generated method stub
  36. 36 //response.getWriter().append("Served at: ").append(request.getContextPath());
  37. 37 request.setCharacterEncoding("utf-8");
  38. 38 response.setCharacterEncoding("utf-8");
  39. 39 String cxfs=request.getParameter("cxfs");
  40. 40 System.out.print(cxfs);
  41. 41
  42. 42 String str=request.getParameter("value");
  43. 43 Dao dao=new Dao();
  44. 44 List<Bean_book> list = null;
  45. 45
  46. 46 try {
  47. 47 if("1".equals(cxfs)){
  48. 48 list=dao.searchByName(str);
  49. 49 }
  50. 50 if("2".equals(cxfs)){
  51. 51 list=dao.searchByWriter(str);
  52. 52 }
  53. 53 } catch (SQLException e) {
  54. 54 // TODO 自动生成的 catch 块
  55. 55 e.printStackTrace();
  56. 56 }
  57. 57 request.setAttribute("list", list);
  58. 58 request.getRequestDispatcher("list book.jsp").forward(request,response);
  59. 59 System.out.print(list.size());
  60. 60 }
  61. 61
  62. 62 /**
  63. 63 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  64. 64 */
  65. 65 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  66. 66 // TODO Auto-generated method stub
  67. 67 doGet(request, response);
  68. 68 }
  69. 69
  70. 70 }
  1. 1 package servlet;
  2. 2
  3. 3 import java.io.IOException;
  4. 4 import java.io.UnsupportedEncodingException;
  5. 5 import java.util.List;
  6. 6
  7. 7 import javax.servlet.ServletException;
  8. 8 import javax.servlet.annotation.WebServlet;
  9. 9 import javax.servlet.http.HttpServlet;
  10. 10 import javax.servlet.http.HttpServletRequest;
  11. 11 import javax.servlet.http.HttpServletResponse;
  12. 12
  13. 13
  14. 14
  15. 15 import java.util.Calendar;
  16. 16 import java.util.Date;
  17. 17 import java.text.ParseException;
  18. 18 import java.text.SimpleDateFormat;
  19. 19
  20. 20 import bean.Bean_user;
  21. 21 import bean.Bean_book;
  22. 22 import bean.Bean_borrowing;
  23. 23 import dao.Dao;
  24. 24
  25. 25 /**
  26. 26 * Servlet implementation class servlet
  27. 27 */
  28. 28 @WebServlet("/Servlet")
  29. 29 public class Servlet extends HttpServlet {
  30. 30 Dao dao = new Dao();
  31. 31 private static final long serialVersionUID = 1L;
  32. 32
  33. 33 /**
  34. 34 * @see HttpServlet#HttpServlet()
  35. 35 */
  36. 36 public Servlet() {
  37. 37 super();
  38. 38 // TODO Auto-generated constructor stub
  39. 39 }
  40. 40
  41. 41 private void insert_user(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {//增
  42. 42 // TODO Auto-generated method stub
  43. 43 request.setCharacterEncoding("utf-8");
  44. 44 int uid = Integer.parseInt(request.getParameter("uid"));
  45. 45 String name = request.getParameter("name");
  46. 46 String sex = request.getParameter("sex");
  47. 47 String college= request.getParameter("college");
  48. 48 String password= request.getParameter("password");
  49. 49 String identity= request.getParameter("identity");
  50. 50 Bean_user bean=new Bean_user(uid,name,sex,college,password,identity);
  51. 51
  52. 52 if(dao.insert_user(bean)) {
  53. 53 request.setAttribute("message", "添加成功");
  54. 54 request.getRequestDispatcher("add user.jsp").forward(request, response);
  55. 55 }
  56. 56 }
  57. 57
  58. 58 private void insert_book(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {//增
  59. 59 // TODO Auto-generated method stub
  60. 60 request.setCharacterEncoding("utf-8");
  61. 61
  62. 62 int id = Integer.parseInt(request.getParameter("id"));
  63. 63 String name = request.getParameter("name");
  64. 64 String writer = request.getParameter("writer");
  65. 65 String press= request.getParameter("press");
  66. 66 int num = Integer.parseInt(request.getParameter("num"));
  67. 67 Bean_book bean=new Bean_book(id,name,writer,press,num);
  68. 68
  69. 69 if(dao.insert_book(bean)) {
  70. 70 request.setAttribute("message", "添加成功");
  71. 71 request.getRequestDispatcher("add book.jsp").forward(request, response);
  72. 72 }
  73. 73 }
  74. 74
  75. 75 private void list(HttpServletRequest request, HttpServletResponse response) throws Exception {
  76. 76 // TODO Auto-generated method stub
  77. 77 request.setCharacterEncoding("UTF-8");
  78. 78 String uid = request.getParameter("uid");
  79. 79 //int uid = Integer.parseInt(request.getParameter("id"));
  80. 80 List<Bean_book> list = dao.list();
  81. 81 request.setAttribute("list", list);
  82. 82 request.setAttribute("uid", uid);
  83. 83
  84. 84 request.getRequestDispatcher("list book.jsp").forward(request,response);
  85. 85 }
  86. 86
  87. 87 private void Mylist(HttpServletRequest request, HttpServletResponse response) throws Exception {
  88. 88 // TODO Auto-generated method stub
  89. 89 request.setCharacterEncoding("UTF-8");
  90. 90 String uid_string = request.getParameter("uid");
  91. 91 int uid = Integer.parseInt(uid_string);
  92. 92 //int uid = Integer.parseInt(request.getParameter("id"));
  93. 93 List<Bean_borrowing> borrower = dao.borrower(uid);
  94. 94 request.setAttribute("list", borrower);
  95. 95 request.setAttribute("uid", uid);
  96. 96
  97. 97 request.getRequestDispatcher("my_list.jsp").forward(request,response);
  98. 98 }
  99. 99
  100. 100 private void list_admin(HttpServletRequest request, HttpServletResponse response) throws Exception {
  101. 101 // TODO Auto-generated method stub
  102. 102 request.setCharacterEncoding("utf-8");
  103. 103 List<Bean_book> list_admin = dao.list();
  104. 104 request.setAttribute("list", list_admin);
  105. 105 request.getRequestDispatcher("delete book.jsp").forward(request,response);
  106. 106 }
  107. 107
  108. 108 private void list_overtime(HttpServletRequest request, HttpServletResponse response) throws Exception {
  109. 109 // TODO Auto-generated method stub
  110. 110 request.setCharacterEncoding("UTF-8");
  111. 111
  112. 112 String uid_string = request.getParameter("uid");
  113. 113 int uid = Integer.parseInt(uid_string);
  114. 114 //int uid = Integer.parseInt(request.getParameter("id"));
  115. 115 List<Bean_borrowing> list_overtime = dao.list_overtime();
  116. 116
  117. 117 request.setAttribute("list", list_overtime);
  118. 118 request.setAttribute("uid", uid);
  119. 119
  120. 120 request.getRequestDispatcher("list_overtime.jsp").forward(request,response);
  121. 121 }
  122. 122
  123. 123
  124. 124
  125. 125 @SuppressWarnings("deprecation")
  126. 126 private void borrow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//改
  127. 127 // TODO Auto-generated method stub
  128. 128 request.setCharacterEncoding("utf-8");
  129. 129 Date date0=new Date();
  130. 130 date0.setMonth(date0.getMonth()+3);
  131. 131 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  132. 132 String date=sdf.format(date0);
  133. 133 int id = Integer.parseInt(request.getParameter("id"));
  134. 134 String name = request.getParameter("name");
  135. 135 String writer = request.getParameter("writer");
  136. 136 String press = request.getParameter("press");
  137. 137
  138. 138 int num= Integer.parseInt(request.getParameter("num"));
  139. 139 num=num-1;
  140. 140
  141. 141 String uid_string = request.getParameter("uid");
  142. 142 int uid = Integer.parseInt(uid_string);
  143. 143
  144. 144
  145. 145 Bean_book bean1=new Bean_book(id,name,writer,press,num);
  146. 146 Bean_borrowing bean2=new Bean_borrowing(id,name,writer,press,date,uid);
  147. 147
  148. 148 dao.update(bean1);
  149. 149 dao.insert_borrowing(bean2);
  150. 150 request.setAttribute("uid", uid);
  151. 151 request.getRequestDispatcher("Servlet?method=list").forward(request, response);
  152. 152 }
  153. 153
  154. 154 private void delete_book(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException {//删
  155. 155 // TODO Auto-generated method stub
  156. 156 request.setCharacterEncoding("UTF-8");
  157. 157 int id=Integer.parseInt(request.getParameter("id"));
  158. 158 dao.delete_book(id); //进行数据库的删除操作
  159. 159 request.setAttribute("message", "删除成功");
  160. 160 request.getRequestDispatcher("Servlet?method=list_admin").forward(request, response);
  161. 161 }
  162. 162
  163. 163 private void return_book(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException {//删
  164. 164 // TODO Auto-generated method stub
  165. 165 request.setCharacterEncoding("UTF-8");
  166. 166 String uid_string = request.getParameter("uid");
  167. 167 int uid = Integer.parseInt(uid_string);
  168. 168 int id=Integer.parseInt(request.getParameter("id"));
  169. 169 dao.return_book(id,uid); //进行数据库的删除操作
  170. 170 request.setAttribute("message", "归还成功");
  171. 171 request.setAttribute("uid", uid);
  172. 172 request.getRequestDispatcher("Servlet?method=Mylist").forward(request, response);
  173. 173 }
  174. 174
  175. 175 /**
  176. 176 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  177. 177 */
  178. 178 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  179. 179 // TODO Auto-generated method stub
  180. 180 request.setCharacterEncoding("utf-8");
  181. 181 String method=request.getParameter("method");
  182. 182 if("insert_user".equals(method)) {
  183. 183 insert_user(request,response);
  184. 184 }
  185. 185 else if("insert_book".equals(method)) {
  186. 186 insert_book(request,response);
  187. 187 }
  188. 188 else if("list".equals(method)) {
  189. 189 try {
  190. 190 list(request,response);
  191. 191 } catch (Exception e) {
  192. 192 // TODO Auto-generated catch block
  193. 193 e.printStackTrace();
  194. 194 }
  195. 195 }
  196. 196 else if("list_overtime".equals(method)) {
  197. 197 try {
  198. 198 list_overtime(request,response);
  199. 199 } catch (Exception e) {
  200. 200 // TODO Auto-generated catch block
  201. 201 e.printStackTrace();
  202. 202 }
  203. 203 }
  204. 204 else if("list_admin".equals(method)) {
  205. 205 try {
  206. 206 list_admin(request,response);
  207. 207 } catch (Exception e) {
  208. 208 // TODO Auto-generated catch block
  209. 209 e.printStackTrace();
  210. 210 }
  211. 211 }
  212. 212 else if("Mylist".equals(method)) {
  213. 213 try {
  214. 214 Mylist(request,response);
  215. 215 } catch (Exception e) {
  216. 216 // TODO Auto-generated catch block
  217. 217 e.printStackTrace();
  218. 218 }
  219. 219 }
  220. 220 else if("borrow".equals(method)) {
  221. 221 borrow(request,response);
  222. 222 }
  223. 223 else if("delete_book".equals(method)) {
  224. 224 try {
  225. 225 delete_book(request,response);
  226. 226 } catch (Exception e) {
  227. 227 // TODO Auto-generated catch block
  228. 228 e.printStackTrace();
  229. 229 }
  230. 230 }
  231. 231 else if("return_book".equals(method)) {
  232. 232 try {
  233. 233 return_book(request,response);
  234. 234 } catch (Exception e) {
  235. 235 // TODO Auto-generated catch block
  236. 236 e.printStackTrace();
  237. 237 }
  238. 238 }
  239. 239 }
  240. 240
  241. 241 /**
  242. 242 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  243. 243 */
  244. 244 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  245. 245 // TODO Auto-generated method stub
  246. 246 doGet(request, response);
  247. 247 }
  248. 248
  249. 249 }

5.前端页面

  1. 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2 pageEncoding="UTF-8"%>
  3. 3 <!DOCTYPE html>
  4. 4 <html>
  5. 5 <head>
  6. 6 <meta charset="UTF-8">
  7. 7 <title>登录</title>
  8. 8 </head>
  9. 9 <body>
  10. 10 <%
  11. 11 Object message = request.getAttribute("message");
  12. 12 if (message != null && !"".equals(message)) {
  13. 13 %>
  14. 14 <script type="text/javascript">
  15. 15 alert("<%=request.getAttribute("message")%>"); //弹出对话框
  16. 16 </script>
  17. 17 <%
  18. 18 }
  19. 19 %>
  20. 20 <form name="user" action="LoginServlet" method="post" onsubmit="return check()">
  21. 21 <table id="addTable" class="table table-bordered" align="center">
  22. 22
  23. 23 <tr class="text-center row">
  24. 24 <td class="col-sm-2">
  25. 25 学号/工号
  26. 26 </td>
  27. 27 <td class="col-sm-4">
  28. 28 <input type="number" class="form-control" name="uid" id="uid" >
  29. 29 </td>
  30. 30 </tr>
  31. 31
  32. 32 <tr class="text-center row">
  33. 33 <td class="col-sm-2">
  34. 34 密码
  35. 35 </td>
  36. 36 <td class="col-sm-4">
  37. 37 <input type="password" class="form-control" name="password" id="password">
  38. 38 </td>
  39. 39 </tr>
  40. 40
  41. 41
  42. 42 <tr class="text-center row">
  43. 43 <td>
  44. 44 登陆身份
  45. 45 </td>
  46. 46 <td colspan="3">
  47. 47 <select class="form-control" id="identity" name="identity">
  48. 48 <option value="读者">读者</option>
  49. 49 <option value="管理员">管理员</option>
  50. 50 </select>
  51. 51 </td>
  52. 52 </tr>
  53. 53
  54. 54
  55. 55 <tr class="text-center row" align="center">
  56. 56 <td colspan="3">
  57. 57 <input type="submit" value="登录" >
  58. 58 </td>
  59. 59 </tr>
  60. 60 </table>
  61. 61
  62. 62 </form>
  63. 63 <script type="text/javascript">
  64. 64 function check(){
  65. 65 if(user.uid.value==""||user.uid.value==null){
  66. 66 alert("学号/工号为空!");
  67. 67 return false;
  68. 68 }
  69. 69 if(user.password.value==""||user.password.value==null){
  70. 70 alert("密码为空!");
  71. 71 return false;
  72. 72 }
  73. 73 }
  74. 74 </script>
  75. 75 </body>
  76. 76 </html>

登陆页面

  1. 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2 pageEncoding="UTF-8"%>
  3. 3 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  4. 4 <!DOCTYPE html>
  5. 5 <html>
  6. 6 <head>
  7. 7 <meta charset="UTF-8">
  8. 8 <title>读者功能页</title>
  9. 9 </head>
  10. 10 <body>
  11. 11 <%
  12. 12 Object uid = request.getAttribute("uid");
  13. 13 if (uid != null && !"".equals(uid)) {
  14. 14 %>
  15. 15 <script type="text/javascript">
  16. 16 alert("欢迎您!读者"+<%=request.getAttribute("uid")%>); //弹出对话框
  17. 17 </script>
  18. 18 <%
  19. 19 }
  20. 20 %>
  21. 21 当前用户:<%=uid %>
  22. 22 <div align="center" font-size="30px">
  23. 23 <h1>读者</h1>
  24. 24 <div>
  25. 25 <a href="Servlet?method=list&uid=<%=uid%>">浏览图书信息</a>
  26. 26 </div>
  27. 27 <div>
  28. 28 <a href="Servlet?method=list&uid=<%=uid%>">查询图书信息</a>
  29. 29 </div>
  30. 30 <div>
  31. 31 <a href="Servlet?method=list&uid=<%=uid%>">借阅图书</a>
  32. 32 </div>
  33. 33 <div>
  34. 34 <a href="Servlet?method=Mylist&uid=<%=uid%>">浏览催还书目</a>
  35. 35 </div>
  36. 36 <div>
  37. 37 <a href="Servlet?method=Mylist&uid=<%=uid%>">归还图书</a>
  38. 38 </div>
  39. 39 </div>
  40. 40 </body>
  41. 41 </html>

读者主页

  1. 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2 pageEncoding="UTF-8"%>
  3. 3 <!DOCTYPE html>
  4. 4 <html>
  5. 5 <head>
  6. 6 <meta charset="UTF-8">
  7. 7 <title>管理员主页</title>
  8. 8 </head>
  9. 9 <body>
  10. 10 <%
  11. 11 Object uid = request.getAttribute("uid");
  12. 12 if (uid != null && !"".equals(uid)) {
  13. 13 %>
  14. 14 <script type="text/javascript">
  15. 15 alert("工号"+<%=request.getAttribute("uid")%>+'你好!'); //弹出对话框
  16. 16 </script>
  17. 17 <%
  18. 18 }
  19. 19 %>
  20. 20 当前用户:<%=uid %>
  21. 21 <div align="center" font-size="30px">
  22. 22 <h1>管理员</h1>
  23. 23 <div>
  24. 24 <a href="add user.jsp">添加用户信息</a>
  25. 25 </div>
  26. 26 <div>
  27. 27 <a href="add book.jsp">添加新书信息</a>
  28. 28 </div>
  29. 29 <div>
  30. 30 <a href="Servlet?method=list_admin">删除书目信息</a>
  31. 31 </div>
  32. 32 <div>
  33. 33 <a href="Servlet?method=list_overtime&uid=<%=uid%>">打印催还书目</a>
  34. 34 </div>
  35. 35 </div>
  36. 36 </body>
  37. 37 </html>

管理员主页

  1. 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2 pageEncoding="UTF-8"%>
  3. 3 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  4. 4 <!DOCTYPE html>
  5. 5 <html>
  6. 6 <head>
  7. 7 <meta charset="UTF-8">
  8. 8 <title>查询</title>
  9. 9 </head>
  10. 10 <body>
  11. 11 <%
  12. 12 Object uid = request.getAttribute("uid");
  13. 13 %>
  14. 14 当前用户:<%=uid%>
  15. 15 <div align="center">
  16. 16 <h1 >信息列表</h1>
  17. 17 <h3>当前时间:<input id="sysDate" style="font-size:18.72px;color:red;width: 320px;text-align: center;"></h3>
  18. 18 <h1>
  19. 19 <form action="SearchServlet" method="post">
  20. 20 <select name="cxfs">
  21. 21 <option id="cxfs"value ="1">书名</option>
  22. 22 <option id="cxfs" value ="2">作者名</option>
  23. 23 </select>
  24. 24 <input type="text" id="value" name="value" placeholder="请输入条件">
  25. 25 <input type="submit" id="select" name="select" value="查询" />
  26. 26 </form>
  27. 27
  28. 28 </h1>
  29. 29 <table >
  30. 30 <tr>
  31. 31 <td>图书编号</td>
  32. 32 <td>书名</td>
  33. 33 <td>作者名</td>
  34. 34 <td>出版社名称</td>
  35. 35 <td>可借阅数量</td>
  36. 36 <td align="center" colspan="2">操作</td>
  37. 37 </tr>
  38. 38 <c:forEach items="${list}" var="item">
  39. 39 <tr>
  40. 40 <td>${item.id}</td>
  41. 41 <td>${item.name}</td>
  42. 42 <td>${item.writer}</td>
  43. 43 <td>${item.press}</td>
  44. 44 <td>${item.num}</td>
  45. 45 <td><a href="Servlet?method=borrow&id=${item.id}&name=${item.name}&writer=${item.writer}&press=${item.press}&num=${item.num}&uid=<%=uid%> "
  46. 46 onclick="next()">订阅</a></td>
  47. 47 </tr>
  48. 48 </c:forEach>
  49. 49 </table>
  50. 50 </div>
  51. 51 </body>
  52. 52
  53. 53 <script type="text/javascript">
  54. 54
  55. 55 /*---------- 动态获取系统当前日期方法start ------*/
  56. 56 setInterval(
  57. 57 "document.getElementById('sysDate').value=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",
  58. 58 1000);
  59. 59 setInterval(
  60. 60 "document.getElementById('sysSysDate').value=new Date().toLocaleString();",
  61. 61 1000);
  62. 62
  63. 63 /*---------- 动态获取系统当前日期方法end ------*/
  64. 64 var d = new Date();
  65. 65 d.setMonth(d.getMonth()+3);
  66. 66 d=d.toLocaleString();
  67. 67
  68. 68
  69. 69 function next(){
  70. 70 alert('订阅成功!还书日期为'+d);
  71. 71 }
  72. 72
  73. 73
  74. 74
  75. 75 </script>
  76. 76 </html>

读者查询书籍

  1. 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2 pageEncoding="UTF-8"%>
  3. 3 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  4. 4 <!DOCTYPE html>
  5. 5 <html>
  6. 6 <head>
  7. 7 <meta charset="UTF-8">
  8. 8 <title>我的借阅</title>
  9. 9 </head>
  10. 10 <body>
  11. 11 <%
  12. 12 Object uid = request.getAttribute("uid");
  13. 13 %>
  14. 14
  15. 15 当前用户:<%=uid%>
  16. 16 <div align="center">
  17. 17 <h1 >我的借阅</h1>
  18. 18 <h3>当前时间:<input id="sysDate" style="font-size:18.72px;color:red;width: 320px;text-align: center;"></h3>
  19. 19
  20. 20 <table >
  21. 21 <tr>
  22. 22 <td>图书编号</td>
  23. 23 <td>书名</td>
  24. 24 <td>作者名</td>
  25. 25 <td>出版社名称</td>
  26. 26 <td>还书日期</td>
  27. 27 <td align="center" colspan="2">操作</td>
  28. 28 </tr>
  29. 29 <c:forEach items="${list}" var="item">
  30. 30 <tr>
  31. 31 <td>${item.id}</td>
  32. 32 <td>${item.name}</td>
  33. 33 <td>${item.writer}</td>
  34. 34 <td>${item.press}</td>
  35. 35 <td>${item.date}</td>
  36. 36 <td><a href="Servlet?method=return_book&id=${item.id}&uid=<%=uid%>"
  37. 37 >还书</a></td>
  38. 38 </tr>
  39. 39 </c:forEach>
  40. 40 </table>
  41. 41 </div>
  42. 42
  43. 43 </body>
  44. 44 <script type="text/javascript">
  45. 45
  46. 46 /*---------- 动态获取系统当前日期方法start ------*/
  47. 47 setInterval(
  48. 48 "document.getElementById('sysDate').value=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",
  49. 49 1000);
  50. 50 setInterval(
  51. 51 "document.getElementById('sysSysDate').value=new Date().toLocaleString();",
  52. 52 1000);
  53. 53
  54. 54 /*---------- 动态获取系统当前日期方法end ------*/
  55. 55
  56. 56 </script>
  57. 57 </html>

根据读者账号查询个人的借阅书籍

  1. 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2 pageEncoding="UTF-8"%>
  3. 3 <!DOCTYPE html>
  4. 4 <html>
  5. 5 <head>
  6. 6 <meta charset="UTF-8">
  7. 7 <title>添加新书信息</title>
  8. 8 </head>
  9. 9 <body>
  10. 10 <%
  11. 11 Object message = request.getAttribute("message");
  12. 12
  13. 13 if (message != null && !"".equals(message)) {
  14. 14 %>
  15. 15 <script type="text/javascript">
  16. 16 alert("<%=request.getAttribute("message")%>"); //弹出对话框
  17. 17 </script>
  18. 18 <%
  19. 19 }
  20. 20 %>
  21. 21
  22. 22 <form action="Servlet?method=insert_book" method="post">
  23. 23
  24. 24 <table id="addTable" class="table table-bordered ">
  25. 25
  26. 26 <tr class="text-center row">
  27. 27 <td class="col-sm-2">
  28. 28 图书编号
  29. 29 </td>
  30. 30 <td class="col-sm-4">
  31. 31 <input type="text" class="form-control" name="id" id="id" >
  32. 32 </td>
  33. 33 </tr>
  34. 34
  35. 35
  36. 36 <tr class="text-center row">
  37. 37 <td class="col-sm-2">
  38. 38 书名
  39. 39 </td>
  40. 40 <td class="col-sm-4">
  41. 41 <input type="text" class="form-control" name="name" id="name" >
  42. 42 </td>
  43. 43 </tr>
  44. 44
  45. 45
  46. 46 <tr class="text-center row">
  47. 47 <td class="col-sm-2">
  48. 48 作者名
  49. 49 </td>
  50. 50 <td class="col-sm-4">
  51. 51 <input type="text" class="form-control" name="writer" id="writer" >
  52. 52 </td>
  53. 53 </tr>
  54. 54
  55. 55 <tr class="text-center row">
  56. 56 <td class="col-sm-2">
  57. 57 出版社名
  58. 58 </td>
  59. 59 <td class="col-sm-4">
  60. 60 <input type="text" class="form-control" name="press" id="press" >
  61. 61 </td>
  62. 62 </tr>
  63. 63
  64. 64 <tr class="text-center row">
  65. 65 <td class="col-sm-2">
  66. 66 可借阅数量
  67. 67 </td>
  68. 68 <td class="col-sm-4">
  69. 69 <input type="text" class="form-control" name="num" id="num" >
  70. 70 </td>
  71. 71 </tr>
  72. 72
  73. 73
  74. 74
  75. 75 </table>
  76. 76 <input type="submit" value="添加" onclick="check()">
  77. 77 </form>
  78. 78 </body>
  79. 79 <script type="text/javascript">
  80. 80 function check() //封装一个<body>中做成点击事件的函数
  81. 81 {
  82. 82 if(document.getElementById('id').value=='') {
  83. 83 alert('图书编号不能为空!');
  84. 84 document.getElementById('id').focus();
  85. 85 return false;
  86. 86 }
  87. 87 if(document.getElementById('name').value==''){
  88. 88 alert('书名不能为空!');
  89. 89 document.getElementById('name').focus();
  90. 90 return false;
  91. 91 }
  92. 92 if(document.getElementById('writer').value=='') {
  93. 93 alert('作者名不能为空!');
  94. 94 document.getElementById('writer').focus();
  95. 95 return false;
  96. 96 }
  97. 97 else if(document.getElementById('press').value==''){
  98. 98 alert('出版社名不能为空!');
  99. 99 document.getElementById('press').focus();
  100. 100 return false;
  101. 101 }
  102. 102 if(document.getElementById('num').value=='') {
  103. 103 alert('借阅数量不能为空!');
  104. 104 document.getElementById('num').focus();
  105. 105 return false;
  106. 106 }
  107. 107 }
  108. 108
  109. 109 </script>
  110. 110 </html>

管理员添加书籍

  1. 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2 pageEncoding="UTF-8"%>
  3. 3 <!DOCTYPE html>
  4. 4 <html>
  5. 5 <head>
  6. 6 <meta charset="UTF-8">
  7. 7 <title>添加读者信息</title>
  8. 8 </head>
  9. 9 <body>
  10. 10 <%
  11. 11 Object message = request.getAttribute("message");
  12. 12
  13. 13 if (message != null && !"".equals(message)) {
  14. 14 %>
  15. 15 <script type="text/javascript">
  16. 16 alert("<%=request.getAttribute("message")%>"); //弹出对话框
  17. 17 </script>
  18. 18 <%
  19. 19 }
  20. 20 %>
  21. 21
  22. 22 <form action="Servlet?method=insert_user" method="post">
  23. 23
  24. 24 <table id="addTable" class="table table-bordered ">
  25. 25
  26. 26 <tr class="text-center row">
  27. 27 <td class="col-sm-2">
  28. 28 账号
  29. 29 </td>
  30. 30 <td class="col-sm-4">
  31. 31 <input type="text" class="form-control" name="uid" id="uid" >
  32. 32 </td>
  33. 33 </tr>
  34. 34
  35. 35
  36. 36 <tr class="text-center row">
  37. 37 <td class="col-sm-2">
  38. 38 姓名
  39. 39 </td>
  40. 40 <td class="col-sm-4">
  41. 41 <input type="text" class="form-control" name="name" id="name" >
  42. 42 </td>
  43. 43 </tr>
  44. 44
  45. 45 <tr class="text-center row">
  46. 46 <td class="col-sm-2">
  47. 47 密码
  48. 48 </td>
  49. 49 <td class="col-sm-4">
  50. 50 <input type="text" class="form-control" name="password" id="password" >
  51. 51 </td>
  52. 52 </tr>
  53. 53
  54. 54 <tr>
  55. 55 <td class="col-sm-2">
  56. 56 性别
  57. 57 </td>
  58. 58 <td class="col-sm-4">
  59. 59 <input type="radio" name="sex" id="sex" value="男">男
  60. 60 <input type="radio" name="sex" id="sex" value="女">女
  61. 61 </td>
  62. 62 </tr>
  63. 63
  64. 64
  65. 65 <tr class="text-center row">
  66. 66 <td class="col-sm-2">
  67. 67 所在学院
  68. 68 </td>
  69. 69 <td class="col-sm-4">
  70. 70 <input type="text" class="form-control" name="college" id="college" >
  71. 71 </td>
  72. 72 </tr>
  73. 73
  74. 74 <tr class="text-center row">
  75. 75 <td>
  76. 76 身份
  77. 77 </td>
  78. 78 <td colspan="3">
  79. 79 <select class="form-control" id="identity" name="identity">
  80. 80 <option value="读者">读者</option>
  81. 81 <option value="管理员">管理员</option>
  82. 82 </select>
  83. 83 </td>
  84. 84 </tr>
  85. 85
  86. 86
  87. 87 </table>
  88. 88 <input type="submit" value="添加" onclick="check()">
  89. 89 </form>
  90. 90 </body>
  91. 91 <script type="text/javascript">
  92. 92 function check() //封装一个<body>中做成点击事件的函数
  93. 93 {
  94. 94 if(document.getElementById('uid').value=='') {
  95. 95 alert('账号不能为空!');
  96. 96 document.getElementById('uid').focus();
  97. 97 return false;
  98. 98 }
  99. 99 if(document.getElementById('password').value==''){
  100. 100 alert('密码不能为空!');
  101. 101 document.getElementById('password').focus();
  102. 102 return false;
  103. 103 }
  104. 104 if(document.getElementById('name').value==''){
  105. 105 alert('姓名不能为空!');
  106. 106 document.getElementById('name').focus();
  107. 107 return false;
  108. 108 }
  109. 109 if(document.getElementById('college').value==''){
  110. 110 alert('所在学院不能为空!');
  111. 111 document.getElementById('college').focus();
  112. 112 return false;
  113. 113 }
  114. 114 if(document.getElementById('sex').value==''){
  115. 115 alert('性别不能为空!');
  116. 116 document.getElementById('sex').focus();
  117. 117 return false;
  118. 118 }
  119. 119 }
  120. 120
  121. 121 </script>
  122. 122 </html>

管理员添加用户

  1. 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2 pageEncoding="UTF-8"%>
  3. 3 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  4. 4 <!DOCTYPE html>
  5. 5 <html>
  6. 6 <head>
  7. 7 <meta charset="UTF-8">
  8. 8 <title>删除</title>
  9. 9 </head>
  10. 10 <body>
  11. 11 <%
  12. 12 Object message = request.getAttribute("message");
  13. 13
  14. 14 if (message != null && !"".equals(message)) {
  15. 15 %>
  16. 16 <script type="text/javascript">
  17. 17 alert("<%=request.getAttribute("message")%>"); //弹出对话框
  18. 18 </script>
  19. 19 <%
  20. 20 }
  21. 21 %>
  22. 22
  23. 23 <div align="center">
  24. 24 <h1 >信息列表</h1>
  25. 25 <h1>
  26. 26 <form action="searchServlet_admin" method="post">
  27. 27 <select name="cxfs">
  28. 28 <option id="cxfs"value ="1">书名</option>
  29. 29 <option id="cxfs" value ="2">作者名</option>
  30. 30 </select>
  31. 31 <input type="text" id="value" name="value" placeholder="请输入条件">
  32. 32 <input type="submit" id="select" name="select" value="查询" />
  33. 33 </form>
  34. 34
  35. 35 </h1>
  36. 36 <table >
  37. 37 <tr>
  38. 38 <td>图书编号</td>
  39. 39 <td>书名</td>
  40. 40 <td>作者名</td>
  41. 41 <td>出版社名称</td>
  42. 42 <td>可借阅数量</td>
  43. 43 <td align="center" colspan="2">操作</td>
  44. 44 </tr>
  45. 45 <c:forEach items="${list}" var="item">
  46. 46 <tr>
  47. 47 <td>${item.id}</td>
  48. 48 <td>${item.name}</td>
  49. 49 <td>${item.writer}</td>
  50. 50 <td>${item.press}</td>
  51. 51 <td>${item.num}</td>
  52. 52 <td><a href="Servlet?method=delete_book&id=${item.id}">删除</a></td>
  53. 53 </tr>
  54. 54 </c:forEach>
  55. 55 </table>
  56. 56 </div>
  57. 57 </body>
  58. 58 </html>

管理员删除书籍

  1. 1 <meta charset="UTF-8">
  2. 2 <title>超时图书</title>
  3. 3 </head>
  4. 4 <body>
  5. 5 <%
  6. 6 Object uid = request.getAttribute("uid");
  7. 7 %>
  8. 8
  9. 9 当前用户:<%=uid%>
  10. 10 <div align="center">
  11. 11 <h1 >催还书目</h1>
  12. 12 <h3>当前时间:<input id="sysDate" style="font-size:18.72px;color:red;width: 320px;text-align: center;"></h3>
  13. 13 <div id="dy">
  14. 14 <table >
  15. 15 <tr>
  16. 16 <td>图书编号</td>
  17. 17 <td>书名</td>
  18. 18 <td>作者名</td>
  19. 19 <td>出版社名称</td>
  20. 20 <td>还书日期</td>
  21. 21 <td>借阅人</td>
  22. 22 </tr>
  23. 23 <c:forEach items="${list}" var="item">
  24. 24 <tr>
  25. 25 <td>${item.id}</td>
  26. 26 <td>${item.name}</td>
  27. 27 <td>${item.writer}</td>
  28. 28 <td>${item.press}</td>
  29. 29 <td>${item.date}</td>
  30. 30 <td>${item.borrower}</td>
  31. 31 </tr>
  32. 32 </c:forEach>
  33. 33 </table>
  34. 34 </div>
  35. 35 </div>
  36. 36 <br>
  37. 37 <table align="center">
  38. 38 <tr><td>
  39. 39 <input type="button" value="打 印" onclick="PrintTable(dy)">
  40. 40 </td></tr>
  41. 41 </table>
  42. 42 </body>
  43. 43
  44. 44 <script type="text/javascript">
  45. 45
  46. 46 /*---------- 动态获取系统当前日期方法start ------*/
  47. 47 setInterval(
  48. 48 "document.getElementById('sysDate').value=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",
  49. 49 1000);
  50. 50 setInterval(
  51. 51 "document.getElementById('sysSysDate').value=new Date().toLocaleString();",
  52. 52 1000);
  53. 53
  54. 54 /*---------- 动态获取系统当前日期方法end ------*/
  55. 55
  56. 56 function PrintTable(Id){
  57. 57 var mStr;
  58. 58 mStr = window.document.body.innerHTML ;
  59. 59 var mWindow = window;
  60. 60 window.document.body.innerHTML =Id.innerHTML;
  61. 61 mWindow.print();
  62. 62 window.document.body.innerHTML = mStr;
  63. 63 }
  64. 64
  65. 65 </script>
  66. 66
  67. 67 </html>

管理员查看有哪些书籍超出借阅时间还没有归还

6.总结

1.增加了登录验证功能,账号信息在数据库中存在才能登录。

2.将账号信息进行跳转传递,在主页显示当前用户

3.完善了图书借阅相关功能,例如查询个人借阅(通过账号信息的参数传递实现)以及催还书目名单打印(JS调用浏览器打印功能)。

4.增加了更多的窗口提示,提升对用户的友好度。

7.数据库后台建表

Java Web下MySQL数据库的增删改查(二)的更多相关文章

  1. Java Web下MySQL数据库的增删改查(一)

    以图书管理系统举例(jsp+servlet+bean) 1.数据库的连接 package db; import java.sql.Connection; import java.sql.DriverM ...

  2. java jdbc 连接mysql数据库 实现增删改查

    好久没有写博文了,写个简单的东西热热身,分享给大家. jdbc相信大家都不陌生,只要是个搞java的,最初接触j2ee的时候都是要学习这么个东西的,谁叫程序得和数据库打交道呢!而jdbc就是和数据库打 ...

  3. Java连接本地MySQL数据库进行增删改查操作

    package Dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStat ...

  4. shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查)

    shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查) Shell脚本与MySQL数据库交互(增删改查) # 环境准备:安装mariadb 数据库 [ro ...

  5. 【转载】通过JDBC对MySQL数据库的增删改查

    通过JDBC进行简单的增删改查(以MySQL为例) 目录 前言:什么是JDBC 一.准备工作(一):MySQL安装配置和基础学习 二.准备工作(二):下载数据库对应的jar包并导入 三.JDBC基本操 ...

  6. 通过jdbc连接MySql数据库的增删改查操作

    一.获取数据库连接 要对MySql数据库内的数据进行增删改查等操作,首先要获取数据库连接 JDBC:Java中连接数据库方式 具体操作如下: 获取数据库连接的步骤: 1.先定义好四个参数 String ...

  7. Java 使用控制台操作实现数据库的增删改查

    使用控制台进行数据库增删改查操作,首先创建一个Java Bean类,实现基础数据的构造,Get,Set方法的实现,减少代码重复性. 基本属性为 学生学号 Id, 学生姓名 Name,学生性别 Sex, ...

  8. 通过Loadruner对mysql数据库进行增删改查

    操作mysql数据库,是在实现mysql数据源配置的基础上操作,可先阅读:loadrunner参数化使用mysql数据源失败解决方法 写之前先理一下,数据库访问流程:打开数据库  --> 数据库 ...

  9. c#winform简单实现Mysql数据库的增删改查的语句

    通过简单的SQL语句实现对数据库的增删改查. 窗口如下: 定义打开与关闭连接函数,方便每次调用: 增加指令: 删除指令: 修改指令: 查找指令: 表格情况:

随机推荐

  1. Manage Historical Snapshots in Sonarqube

    Login as admin, go to a dashboard of a project, then click "Configuration -> History" a ...

  2. Docker搭建Svn服务器

    一.下载镜像 # 搜索镜像 docker search svn # 下载镜像 docker pull garethflowers/svn-server 二.启动镜像 # 编辑配置文件 vim dock ...

  3. Nginx-出现-403-Forbidden

    步骤一: 检查目录权限.权限不足的就加个权限吧. 例子:chmod -R 755 / var/www 步骤二: 打开nginx.conf 例子:vim /etc/nginx/nginx.conf 把 ...

  4. 01.SpringMVC之概述

    springMVC架构 SpringMVC是Spring框架的一个模块,Spring和SpringMVC无需通过中间整合层进行整合.SpringMVC是基于MVC架构的WEB框架.SpringMVC框 ...

  5. 传统表单提交文件上传,以及FormData异步ajax上传文件

    传统的文件上传: 只用将form表单的entype修改成multipart/form-data,然后就可以进行文件上传,这种方式常用并且简单. 以下是另一种方式FormData,有时候我们需要ajax ...

  6. 关于oracle样例数据库emp、dept、salgrade的mysql脚本复杂查询分析

    大家可以自行网上找资源(网上资源比较多,不建议下载我的),也可以在我这里下载: 1.取得每个部门最高薪水的人员名称:正确   一共有4个单位,要进行左外连接 其中一个单位没得员工 SELECT dep ...

  7. 初始C3P0连接池

    C3P0连接池只需要一个jar包: 其中我们可以看到有三个jar包: 属于C3P0的jar包只有一个,另外两个是测试时使用的JDBC驱动:一个是mysql的,一个是oracle的: 可以看到在src下 ...

  8. Python和java的选择

    它是什么? Java是一种通用的面向对象的编程语言,主要用于开发从移动应用程序到Web到企业应用程序的各种应用程序. Python是一种高级的面向对象的编程语言,主要用于Web开发,人工智能,机器学习 ...

  9. JAVA《多线程多人上线通知案例》

    package com.wangbiao.palyermanager; import com.wangbiao.player.Player; /** * TODO * * @author wangbi ...

  10. nginx 开启,关闭,重启

    2021-08-191. 启动 # 判断配置文件是否正确 cd /usr/local/nginx/sbin ./nginx -t # 启动 cd usr/local/nginx/sbin ./ngin ...