From bc431ff4daddbde3690c0f0a7ec62c531cf7ed86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=8E=E9=B8=A0?= <3322619096@qq.com> Date: Wed, 5 Jun 2024 20:42:31 +0800 Subject: [PATCH 1/2] feat:0605 --- .../index.jsp" | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 "work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index.jsp" diff --git "a/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index.jsp" "b/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index.jsp" new file mode 100644 index 00000000..bc388ea8 --- /dev/null +++ "b/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index.jsp" @@ -0,0 +1,101 @@ +<%@ page import="com.java.minxi.java_20240604.java_2301关松涛_2344310112.UerInfo" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="java.util.Objects" %> +<%@ page import="java.sql.*" %> +<%@ page language="java" contentType="text/html; ISO-8859-1" pageEncoding="UTF-8" %> + + + 学生信息查询 + + +<% + class UerInfo { + public boolean toString; + private Integer id; + private String username; + private Integer userphone; + + public UerInfo() { + + } + + public UerInfo(Integer id, String username, Integer userphone) { + this.id = id; + this.username = username; + this.userphone = userphone; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Integer getUserphone() { + return userphone; + } + + public void setUserphone(Integer userphone) { + this.userphone = userphone; + } + + @Override + public String toString() { + return "UerInfo{" + + "id=" + id + + ", username='" + username + '\'' + + ", userphone=" + userphone + + '}'; + } + } + +%> +<% + Connection connection=null; + Statement statement=null; + ResultSet resultSet=null; + UerInfo uerInfo = new UerInfo(); + ArrayList objects = new ArrayList<>(); + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + String url="jdbc:mysql://localhost:3306/student?serverTimezone/Shanghai"; + String username="root"; + String password="123456"; + connection = DriverManager.getConnection(url, username, password); + String sql="select id,user_name,user_phone from user_info;"; + statement = connection.createStatement(); + resultSet = statement.executeQuery(sql); + while (resultSet.next()){ + int id = resultSet.getInt("id"); + String name = resultSet.getString("username"); + String phone = resultSet.getString("userphone"); + out.print(UerInfo.); + } + for (uerInfo: + uerInfo) { + + } + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } finally { + try { + resultSet.close(); + statement.close(); + connection.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } +%> + + \ No newline at end of file -- Gitee From 38e78e9295240be6690f004e7e73ba340b37034b Mon Sep 17 00:00:00 2001 From: guan-songtao <3322619096@qq.com> Date: Wed, 5 Jun 2024 23:53:14 +0800 Subject: [PATCH 2/2] feat:0603 --- .../index.jsp" | 133 ++++++++++-------- .../index1.jsp" | 24 ++++ 2 files changed, 96 insertions(+), 61 deletions(-) create mode 100644 "work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index1.jsp" diff --git "a/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index.jsp" "b/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index.jsp" index bc388ea8..502c6880 100644 --- "a/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index.jsp" +++ "b/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index.jsp" @@ -1,4 +1,4 @@ -<%@ page import="com.java.minxi.java_20240604.java_2301关松涛_2344310112.UerInfo" %> + <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Objects" %> <%@ page import="java.sql.*" %> @@ -9,93 +9,104 @@ <% - class UerInfo { - public boolean toString; - private Integer id; - private String username; - private Integer userphone; - - public UerInfo() { - - } +class UserInfo{ + private int id; + private String name; + private String phone; - public UerInfo(Integer id, String username, Integer userphone) { - this.id = id; - this.username = username; - this.userphone = userphone; - } + public UserInfo() { + } - public Integer getId() { - return id; - } + public UserInfo(int id, String name, String phone) { + this.id = id; + this.name = name; + this.phone = phone; + } - public void setId(Integer id) { - this.id = id; - } + public int getId() { + return id; + } - public String getUsername() { - return username; - } + public void setId(int id) { + this.id = id; + } - public void setUsername(String username) { - this.username = username; - } + public String getName() { + return name; + } - public Integer getUserphone() { - return userphone; - } + public void setName(String name) { + this.name = name; + } - public void setUserphone(Integer userphone) { - this.userphone = userphone; - } + public String getPhone() { + return phone; + } - @Override - public String toString() { - return "UerInfo{" + - "id=" + id + - ", username='" + username + '\'' + - ", userphone=" + userphone + - '}'; - } + public void setPhone(String phone) { + this.phone = phone; } + @Override + public String toString() { + return "UserInfo{" + + "id=" + id + + ", name='" + name + '\'' + + ", phone='" + phone + '\'' + + '}'; + } +} %> + <% Connection connection=null; - Statement statement=null; + PreparedStatement preparedStatement = null; ResultSet resultSet=null; - UerInfo uerInfo = new UerInfo(); - ArrayList objects = new ArrayList<>(); + ArrayList objects = new ArrayList<>(); try { Class.forName("com.mysql.cj.jdbc.Driver"); - String url="jdbc:mysql://localhost:3306/student?serverTimezone/Shanghai"; + String url = "jdbc:mysql://127.0.0.1:3306/student?serverTimezone=Asia/Shanghai"; String username="root"; String password="123456"; connection = DriverManager.getConnection(url, username, password); String sql="select id,user_name,user_phone from user_info;"; - statement = connection.createStatement(); - resultSet = statement.executeQuery(sql); +// statement = connection.createStatement(); + preparedStatement = connection.prepareStatement(sql); + resultSet = preparedStatement.executeQuery(); while (resultSet.next()){ + UserInfo userInfo = new UserInfo(); int id = resultSet.getInt("id"); - String name = resultSet.getString("username"); - String phone = resultSet.getString("userphone"); - out.print(UerInfo.); + String name = resultSet.getString("user_name"); + String phone = resultSet.getString("user_phone"); + userInfo.setId(id); + userInfo.setName(name); + userInfo.setPhone(phone); + objects.add(userInfo); } - for (uerInfo: - uerInfo) { - - } - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + out.print(objects); + } catch (Exception e) { + e.printStackTrace(); } finally { try { - resultSet.close(); - statement.close(); - connection.close(); - } catch (SQLException e) { - throw new RuntimeException(e); + if (null != preparedStatement) { + preparedStatement.close(); + } + if (null != resultSet) { + resultSet.close(); + } + if (null != connection) { + connection.close(); + } + } catch (Exception e) { + e.printStackTrace(); } } %> + + + + + + \ No newline at end of file diff --git "a/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index1.jsp" "b/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index1.jsp" new file mode 100644 index 00000000..b0ddcb77 --- /dev/null +++ "b/work/com/java/minxi/java_20240604/java_2301\345\205\263\346\235\276\346\266\233_2344310112/index1.jsp" @@ -0,0 +1,24 @@ +<%@ page language="java" contentType="text/html; ISO-8859-1" pageEncoding="UTF-8" %> + + + + + + + Document + + + <% + String a = request.getParameter("a"); + String b = request.getParameter("b"); + String c = request.getParameter("c"); + %> +<%=a%> +
+ <%=b%> +
+ <%=c%> +
+ + \ No newline at end of file -- Gitee