---
# System prepended metadata

title: JV27 課題No.04
tags: [課題]

---

# JV27 課題No.04
###### tags: `課題`

option1(DELETEした場合の話)
削除した場合クラス内の出席番号を01~から再編成する

<span style="font-size: 100px">OP1 DONE！</span>
:fire:



option2
クラス移動した場合、移動前、移動後のクラス内の出席番号をカナの50音順となるように01~再編成する

<span style="font-size: 100px">OP2 DONE！</span>

HTML区分選択　→
サーブレット　名簿一覧　表情　→
サーブレット　対象レコード　検索 →
JSP データ表示　変更 →
サーブレット　データベース更新

```java= 
//これで送って
request.setAttribute("属性名", インスタンス);
// これで受け取る
request.getAttribute("属性名");
```

```htmlembedded=

<!-- class_update.html -->
<!DOCTYPE html>
<html lang="jp">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>クラス名簿 - 更新</title>
  </head>
  <body>
    <div
      class=""
    >
      <div class="">
        <div class="">
          クラス名簿 - 更新
        </div>
        <form action="./servlet/class_update_select" method="POST">
          <label class="cursor-pointer label">
            <span class="label-text">更新対象クラス</span>
          </label>
          <select
            name="CLASS_NO"
            class=""
          >
            <option value="AT11A192" selected>AT11A192</option>
            <option value="AT11B203">AT11B203</option>
            <option value="CG11A172">CG11A172</option>
            <option value="IT11A172">IT11A172</option>
            <option value="AT12A165">AT12A165</option>
            <option value="AT12B165">AT12B165</option>
            <option value="IH12A101">IH12A101</option>
            <option value="IW12A185">IW12A185</option>
            <option value="AT13A223">AT13A223</option>
            <option value="AP13A223">AP13A223</option>
            <option value="IH13A223">IH13A223</option>
            <option value="IW13A187">IW13A187</option>
            <option value="CD13A166">CD13A166</option>
            <option value="AP14A226">AP14A226</option>
            <option value="AT14A226">AT14A226</option>
            <option value="IH14A223">IH14A223</option>
            <option value="CT14A187">CT14A187</option>
            <option value="IW14A187">IW14A187</option>
            <option value="xx14Axx">xx14Axx</option>
          </select>
          <div class="">
            <a href="class_index.html" class="">
              戻る
            </a>
            <button class="">検索</button>
          </div>
        </form>
      </div>
    </div>
  </body>
</html>

```

```java=

// class_update.java
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class class_update_select extends HttpServlet {
	
	public void doPost (
		HttpServletRequest req,
		HttpServletResponse res )
		throws ServletException , IOException {

		final String URL = "jdbc:mysql://localhost/nhs00157db?useUnicode=true&characterEncoding=UTF-8";
		final String USER = "miyasan";
		final String PASSWORD = "0301";
		final String DRIVER = "com.mysql.jdbc.Driver";

		Connection con = null;
		Statement stmt = null;

		String class_no,gakuseki_no,syusseki_no,simei_1,simei_2,kana_1,kana_2,umare;
		PrintWriter out;
		req.setCharacterEncoding("UTF-8");
		res.setContentType("text/html;charset=UTF-8");
		out = res.getWriter();

		String searchStr = "";
		String selectStr = req.getParameter("CLASS_NO");
		
 		StringBuffer sb = new StringBuffer();
		sb.append("<html>");
			sb.append("<head>");
				sb.append("<title>名簿更新</title>");
			sb.append("</head>");
			sb.append("<body>");
				sb.append("<div class=''>");
					sb.append("<div class=''>名簿更新</div>");
					sb.append("<div class=''>");
						sb.append("<div class=''>削除する学生を選択してください</div>");
						sb.append("<form action='./class_update_userFetch' method='POST'>");
							sb.append("<table class=''>");
                                sb.append("<tr>");
                                    sb.append("<th>");
                                        sb.append("更新");
                                    sb.append("</th>");
                                    sb.append("<th>");
                                        sb.append("出席番号");
                                    sb.append("</th>");
                                    sb.append("<th>");
                                        sb.append("学籍番号");
                                    sb.append("</th>");
                                    sb.append("<th>");
                                        sb.append("氏名（姓）");
                                    sb.append("</th>");
                                    sb.append("<th>");
                                        sb.append("氏名（名）");
                                    sb.append("</th>");
                                    sb.append("<th>");
                                        sb.append("カナ（姓）");
                                    sb.append("</th>");
                                    sb.append("<th>");
                                        sb.append("カナ（名）");
                                    sb.append("</th>");
                                    sb.append("<th>");
                                        sb.append("生年月日");
                                    sb.append("</th>");
                                sb.append("</tr>");
								try {
									Class.forName(DRIVER);
									con = DriverManager.getConnection(URL,USER,PASSWORD);
									stmt = con.createStatement();
									StringBuffer query = new StringBuffer();
									query.append("select * from class_table where ");
									query.append("class_no = '");
									query.append(selectStr);
									query.append("' order by syusseki_no");
									ResultSet rs = stmt.executeQuery(query.toString());
									while (rs.next()) {
										syusseki_no = rs.getString("syusseki_no");
										gakuseki_no = rs.getString("gakuseki_no");
										simei_1 = rs.getString("simei_1");
										simei_2 = rs.getString("simei_2");
										kana_1 = rs.getString("kana_1");
										kana_2 = rs.getString("kana_2");
										umare = rs.getString("umare");
                                        sb.append("<tr>");
                                            sb.append("<td>");
                                                sb.append("<label>");
                                                    sb.append("<input class='' type='radio' name='UPDATE_ID' value='" + gakuseki_no + "' />");
                                                sb.append("<label>");
                                            sb.append("</td>");
                                            sb.append("<td>");
                                                sb.append(syusseki_no);
                                            sb.append("</td>");
                                            sb.append("<td>");
                                                sb.append(gakuseki_no);
                                            sb.append("</td>");
                                            sb.append("<td>");
                                                sb.append(simei_1);
                                            sb.append("</td>");
                                            sb.append("<td>");
                                                sb.append(simei_2);
                                            sb.append("</td>");
                                            sb.append("<td>");
                                                sb.append(kana_1);
                                            sb.append("</td>");
                                            sb.append("<td>");
                                                sb.append(kana_2);
                                            sb.append("</td>");
                                            sb.append("<td>");
                                                sb.append(umare);
                                            sb.append("</td>");
                                        sb.append("</tr>");
									}
							sb.append("</table>");
							sb.append("<div class=''>");
								sb.append("<button class=''>確認</button>");
							sb.append("</div>");
						sb.append("</form>");
						sb.append("<div class=''>");
							sb.append("<a href='/JV27/class_update.html' class=''>検索に戻る</a>");
							sb.append("<a href='/JV27/class_index.html' class=''>ホームに戻る</a>");
						sb.append("</div>");
					sb.append("</div>");
				sb.append("</div>");
			sb.append("</body>");
		sb.append("</html>");

		out.println(sb.toString());
		stmt.close();
		con.close();
	} catch (SQLException ex) {
		out.println(" ---- SQL Exception ----");
		out.println(" ---- Error Message ----");
		while (ex != null) {
			out.println(ex.getMessage());
			ex = ex.getNextException();
		}
	} catch (Exception ex) {
		ex.printStackTrace(out);
	}
}}
```

```java=
// class_update_userFetch.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class class_update_userFetch extends HttpServlet {
	public void doPost (
			HttpServletRequest req,
			HttpServletResponse res )
		throws ServletException , IOException {
			req.setCharacterEncoding("UTF-8");
			res.setContentType("text/html; charset=UTF-8");
			
		final String URL = "jdbc:mysql://localhost/nhs00157db?useUnicode=true&characterEncoding=UTF-8";
		final String USER = "miyasan";
		final String PASSWORD = "0301";
		final String DRIVER = "com.mysql.jdbc.Driver";

		Connection con = null;
		Statement stmt = null;
		String class_no,gakuseki_no,syusseki_no,simei_1,simei_2,kana_1,kana_2,umare;
		PrintWriter out;
		req.setCharacterEncoding("UTF-8");
		res.setContentType("text/html;charset=UTF-8");
		out = res.getWriter();
		
		String update_idStr = req.getParameter("UPDATE_ID");
		
		try {
			Class.forName(DRIVER);
			con = DriverManager.getConnection(URL,USER,PASSWORD);
			stmt = con.createStatement();
			StringBuffer query = new StringBuffer();
			query.append("select * from class_table where ");
			query.append("gakuseki_no = '");
			query.append(update_idStr);
			query.append("'");
			ResultSet rs = stmt.executeQuery(query.toString());
			
			while (rs.next()) {
				req.setAttribute("class_no", rs.getString("class_no"));
				req.setAttribute("syusseki_no", rs.getString("syusseki_no"));
				req.setAttribute("gakuseki_no", rs.getString("gakuseki_no"));
				req.setAttribute("simei_1", rs.getString("simei_1"));
				req.setAttribute("simei_2", rs.getString("simei_2"));
				req.setAttribute("kana_1", rs.getString("kana_1"));
				req.setAttribute("kana_2", rs.getString("kana_2"));
				req.setAttribute("umare", rs.getString("umare"));
			}
			
			ServletContext sc = getServletContext();
			sc.getRequestDispatcher("/class_userInfoEdit.jsp").forward(req, res);
			
		} catch (SQLException ex) {
			out.println(" ---- SQL Exception ----");
			out.println(" ---- Error Message ----");
			while (ex != null) {
				out.println(ex.getMessage());
				ex = ex.getNextException();
			}
		} catch (Exception ex) {
			ex.printStackTrace(out);
		}
	}
}

```

```htmlmixed=

// class_userInfoEdit.jsp

<%@ page contentType="text/html;charset=UTF-8" %> 
<%
	response.setContentType("text/html; charset=UTF-8"); %> <% String class_no =
	request.getAttribute("class_no").toString(); String syusseki_no =
	request.getAttribute("syusseki_no").toString(); String gakuseki_no =
	request.getAttribute("gakuseki_no").toString(); String simei_1 =
	request.getAttribute("simei_1").toString(); String simei_2 =
	request.getAttribute("simei_2").toString(); String kana_1 =
	request.getAttribute("kana_1").toString(); String kana_2 =
	request.getAttribute("kana_2").toString(); String umare =
	request.getAttribute("umare").toString(); 
	
	String[] classList = {"AT11A192", "AT11B203", "CG11A172", "IT11A172", "AT12A165",
	 "AT12B165", "IH12A101", "IW12A185", "AT13A223", "AP13A223", "IH13A223", "IW13A187",
	 "CD13A166", "AP14A226", "AT14A226", "IH14A223", "CT14A187", "IW14A187", "xx14Axx"};
%>

<html>
  <head>
    <title>class_userInfoEdit.jsp</title>
  </head>
  <body>
    <div
      class=""
    >
      <div class="">
        <form action="./class_update_done" method="POST">
          <div class="">
            <div class="">
              クラス名簿 - 登録
            </div>
				<table class="">
					<tbody>
						<tr>
							<td class=''>クラス記号</td> 
							<td>
								<select
									name="class_no"
									class=""
									>
										<option value="" disabled>クラス記号を選択してください</option>
										<% for (int i = 0; i < classList.length; i++) { %>
											<option value="<%= classList[i] %>"
												<% if(classList[i].equals(class_no)) { %>
													selected
													<% } %>
													>
													<%= classList[i] %>
											</option>            
										<% } %>
								</select>
							</td>
						</tr>
						<tr>
							<td>出席番号</td> 
							<td>
							<input
								type="text"
								name="syusseki_no"
								value="<%= syusseki_no %>"
								class=""
								placeholder="出席番号"
								/>
							</td>
						</tr>
						<tr>
							<td>学籍番号</td> 
							<td>
							<input
								type="text"
								name="gakuseki_no"
								value="<%= gakuseki_no %>"
								class=""
								placeholder="学籍番号"
								/>
							</td>
						</tr>
						<tr>
							<td>氏名(姓)</td> 
							<td>
							<input
								type="text"
								name="simei_1"
								value="<%= simei_1 %>"
								class=""
								placeholder="氏名(姓)"
								/>
							</td>
						</tr>
						<tr>
							<td>氏名(名)</td> 
							<td>
							<input
								type="text"
								name="simei_2"
								value="<%= simei_2 %>"
								class=""
								placeholder="氏名(名)"
								/>
							</td>
						</tr>
						</tr>
						<tr>
							<td>カナ(姓)</td> 
							<td>
							<input
								type="text"
								name="kana_1"
								value="<%= kana_1 %>"
								class=""
								placeholder="カナ(姓)"
								/>
							</td>
						</tr>
						</tr>
						<tr>
							<td>カナ(名)</td> 
							<td>
							<input
								type="text"
								name="kana_2"
								value="<%= kana_2 %>"
								class=""
								placeholder="カナ(名)"
								/>
							</td>
						</tr>
						</tr>
						<tr>
							<td>生年月日</td> 
							<td>
							<input
								type="text"
								name="umare"
								value="<%= umare %>"
								class=""
								placeholder="生年月日"
								/>
							</td>
						</tr>
						<tr>
							<th colspan="2" class="">
								<button class="">更新</button>
							</th>
						</tr>
					</tbody>
				</table>
          </div>
        </form>
      </div>
    </div>
  </body>
</html>

```

```java=
// class_update_done.java
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class class_update_done extends HttpServlet {
	
	public void doPost (
		HttpServletRequest req,
		HttpServletResponse res )
		throws ServletException , IOException {

		final String URL = "jdbc:mysql://localhost/nhs00157db?useUnicode=true&characterEncoding=UTF-8";
		final String USER = "miyasan";
		final String PASSWORD = "0301";
		final String DRIVER = "com.mysql.jdbc.Driver";

		Connection con = null;
		Statement stmt = null;

		String class_no,gakuseki_no,syusseki_no,simei_1,simei_2,kana_1,kana_2,umare;
		PrintWriter out;
		req.setCharacterEncoding("UTF-8");
		res.setContentType("text/html;charset=UTF-8");
		out = res.getWriter();

		String class_noStr = req.getParameter("class_no");
		String syusseki_noStr = req.getParameter("syusseki_no");
		Integer syusseki_noInt = Integer.parseInt(syusseki_noStr);
		String gakuseki_noStr = req.getParameter("gakuseki_no");
		String simei_1Str = req.getParameter("simei_1");
		String simei_2Str = req.getParameter("simei_2");
		String kana_1Str = req.getParameter("kana_1");
		String kana_2Str = req.getParameter("kana_2");
		String umareStr = req.getParameter("umare");
		String _syusseki_noStr = "";

		try {
			Class.forName(DRIVER);
			con = DriverManager.getConnection(URL,USER,PASSWORD);
			stmt = con.createStatement();
			StringBuffer query = new StringBuffer();

			if(syusseki_noInt < 10){
				_syusseki_noStr = String.format("%02d", syusseki_noInt);
			} else {
				_syusseki_noStr = String.valueOf(syusseki_noInt);
			}
			
			query = new StringBuffer();
			query.append("update class_table set class_no = '");
			query.append(class_noStr);
			query.append("', syusseki_no = '");
			query.append(_syusseki_noStr);
			query.append("', simei_1 = '");
			query.append(simei_1Str);
			query.append("', simei_2 = '");
			query.append(simei_2Str);
			query.append("', kana_1 = '");
			query.append(kana_1Str);
			query.append("', kana_2 = '");
			query.append(kana_2Str);
			query.append("', umare = '");
			query.append(umareStr);
			query.append("' where gakuseki_no = '");
			query.append(gakuseki_noStr);
			query.append("'");
			
			stmt.executeUpdate(query.toString());

			StringBuffer sb = new StringBuffer();
			sb.append("<html>");
				sb.append("<head>");
					sb.append("<title>名簿更新完了</title>");
				sb.append("</head>");
				sb.append("<body>");
					sb.append("<div class=''>");
						sb.append("<div class=''>名簿更新</div>");
						sb.append("<div class=''>");
							sb.append("<div class=''>名簿更新完了</div>");
							sb.append("<div class='flex justify-center pt-5'>");
								sb.append("<a href='/JV27/class_update.html' class=''>更新に戻る</a>");
								sb.append("<a href='/JV27/class_index.html' class=''>ホームに戻る</a>");
							sb.append("</div>");
						sb.append("</div>");
					sb.append("</div>");
				sb.append("</body>");
			sb.append("</html>");
			out.println(sb.toString());
			stmt.close();
			con.close();
		}
		catch (SQLException ex) {
			out.println(" ---- SQL Exception ----");
			out.println(" ---- Error Message ----");
			while (ex != null) {
				out.println(ex.getMessage());
				ex = ex.getNextException();
			}
		} catch (Exception ex) {
			ex.printStackTrace(out);
		}
	}
}

```

```java=
// OP1
// class_update_deleteSort.java
// だれかリファクタよろしく
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.HashMap;
import java.util.ArrayList;

public class class_update_deleteSort extends HttpServlet {
	
	public void doPost (
		HttpServletRequest req,
		HttpServletResponse res )
		throws ServletException , IOException {

		final String URL = "jdbc:mysql://localhost/nhs00157db?useUnicode=true&characterEncoding=UTF-8";
		final String USER = "miyasan";
		final String PASSWORD = "0301";
		final String DRIVER = "com.mysql.jdbc.Driver";

		Connection con = null;
		Statement stmt = null;
		
		HashMap<String,String> map = null;
	    ArrayList<HashMap> list = null;
	    list = new ArrayList<HashMap>();

		PrintWriter out;
		req.setCharacterEncoding("UTF-8");
		res.setContentType("text/html;charset=UTF-8");
		out = res.getWriter();
		
		String class_no,gakuseki_no,syusseki_no,simei_1,simei_2,kana_1,kana_2,umare;
		String delete_class_idStr = req.getParameter("DELETE_CLASS_NO");
		String delete_gakuseki_idStr = req.getParameter("DELETE_GAKUSEKI_NO");
		String _syusseki_noStr = "";

		try {
			Class.forName(DRIVER);
			con = DriverManager.getConnection(URL,USER,PASSWORD);
			stmt = con.createStatement();
			
			//一件削除		
			StringBuffer query = new StringBuffer();
			query.append("delete from class_table where gakuseki_no = '");
			query.append(delete_gakuseki_idStr);
			query.append("'");
			stmt.executeUpdate(query.toString());
			
			//全件取得		
			query = new StringBuffer();
			query.append("select gakuseki_no from class_table where class_no = '");
			query.append(delete_class_idStr);
			query.append("' order by syusseki_no");
			ResultSet rs = stmt.executeQuery(query.toString());
			while (rs.next()) {
				map = new HashMap<String,String>();
	            map.put("gakuseki_no",rs.getString("gakuseki_no"));
	            list.add(map);
			}
			System.out.print(list);
			
			//全件更新 
			for (int i = 0; i < list.size(); i++) {
				query = new StringBuffer();
				query.append("update class_table set syusseki_no = '");
				if (i < 10) {
					_syusseki_noStr = String.format("%02d", i + 1);
					query.append(_syusseki_noStr);
				} else {
					_syusseki_noStr = String.valueOf(i + 1);
					query.append(_syusseki_noStr);
				}
				query.append("' where gakuseki_no = '");
				query.append(list.get(i).get("gakuseki_no"));
				query.append("'");
				stmt.executeUpdate(query.toString());
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("<html>");
				sb.append("<head>");
					sb.append("<title>名簿削除&クラス並び替え完了</title>");
				sb.append("</head>");
			sb.append("<body>");
        		sb.append("<div class=''>");
						sb.append("<div class=''>名簿削除&クラス並び替え</div>");
						sb.append("<div class='px-5'>");
							sb.append("<div class=''>名簿削除&クラス並び替え完了</div>");
							sb.append("<div class=''>");
								sb.append("<a href='/JV27/class_update.html' class=''>更新に戻る</a>");
								sb.append("<a href='/JV27/class_index.html' class=''>ホームに戻る</a>");
							sb.append("</div>");
						sb.append("</div>");
					sb.append("</div>");
				sb.append("</div>");
			sb.append("</body>");
		sb.append("</html>");
		out.println(sb.toString());
		stmt.close();
		con.close();
		}
		catch (SQLException ex) {
			out.println(" ---- SQL Exception ----");
			out.println(" ---- Error Message ----");
			while (ex != null) {
				out.println(ex.getMessage());
				ex = ex.getNextException();
			}
		} catch (Exception ex) {
			ex.printStackTrace(out);
		}
	}
}

```

```htmlmixed=
<!-- OP2用 -->
<!-- class_userInfoEdit.jsp -->
<%@ page contentType="text/html;charset=UTF-8" %> 
<%
	response.setContentType("text/html; charset=UTF-8"); %> <% String class_no =
	request.getAttribute("class_no").toString(); String syusseki_no =
	request.getAttribute("syusseki_no").toString(); String gakuseki_no =
	request.getAttribute("gakuseki_no").toString(); String simei_1 =
	request.getAttribute("simei_1").toString(); String simei_2 =
	request.getAttribute("simei_2").toString(); String kana_1 =
	request.getAttribute("kana_1").toString(); String kana_2 =
	request.getAttribute("kana_2").toString(); String umare =
	request.getAttribute("umare").toString(); 
	
	String[] classList = {"AT11A192", "AT11B203", "CG11A172", "IT11A172", "AT12A165",
	 "AT12B165", "IH12A101", "IW12A185", "AT13A223", "AP13A223", "IH13A223", "IW13A187",
	 "CD13A166", "AP14A226", "AT14A226", "IH14A223", "CT14A187", "IW14A187", "xx14Axx"};
%>

<html>
  <head>
    <title>class_userInfoEdit.jsp</title>
  </head>
  <body>
    <div
      class=""
    >
      <div class="">
        <form action="./class_update_done2" method="POST">
          <div class="">
            <div class="">
              クラス名簿 - 登録
            </div>
				<table class="">
					<tbody>
						<tr>
							<td class=''>クラス記号</td> 
							<td>
								<select
									name="CLASS_NO"
									class=""
									>
										<option value="" disabled>クラス記号を選択してください</option>
										<% for (int i = 0; i < classList.length; i++) { %>
											<option value="<%= classList[i] %>"
												<% if(classList[i].equals(class_no)) { %>
													selected
													<% } %>
													>
													<%= classList[i] %>
											</option>            
										<% } %>
								</select>
							</td>
						</tr>
						<tr>
							<td>出席番号</td> 
							<td>
							<input
								type="text"
								name="SYUSSEKI_NO"
								value="<%= syusseki_no %>"
								class=""
								placeholder="出席番号"
								/>
							</td>
						</tr>
						<tr>
							<td>学籍番号</td> 
							<td>
							<input
								type="text"
								name="GAKUSEKI_NO"
								value="<%= gakuseki_no %>"
								class=""
								placeholder="学籍番号"
								/>
							</td>
						</tr>
						<tr>
							<td>氏名(姓)</td> 
							<td>
							<input
								type="text"
								name="SIMEI_1"
								value="<%= simei_1 %>"
								class=""
								placeholder="氏名(姓)"
								/>
							</td>
						</tr>
						<tr>
							<td>氏名(名)</td> 
							<td>
							<input
								type="text"
								name="SIMEI_2"
								value="<%= simei_2 %>"
								class=""
								placeholder="氏名(名)"
								/>
							</td>
						</tr>
						</tr>
						<tr>
							<td>カナ(姓)</td> 
							<td>
							<input
								type="text"
								name="KANA_1"
								value="<%= kana_1 %>"
								class=""
								placeholder="カナ(姓)"
								/>
							</td>
						</tr>
						</tr>
						<tr>
							<td>カナ(名)</td> 
							<td>
							<input
								type="text"
								name="KANA_2"
								value="<%= kana_2 %>"
								class=""
								placeholder="カナ(名)"
								/>
							</td>
						</tr>
						</tr>
						<tr>
							<td>生年月日</td> 
							<td>
							<input
								type="text"
								name="UMARE"
								value="<%= umare %>"
								class=""
								placeholder="生年月日"
								/>
							</td>
						</tr>
						<tr>
							<th colspan="2">
								<button class="">更新</button>
						        <input type="hidden" name="_CLASS_NO" value="<%= class_no %>"/>
        						</form>
							</th>
						</tr>
						<tr>	
							<th colspan="2">
								<form action="./class_update_deleteSort" method="POST">
									<input
										type="hidden"
										name="DELETE_CLASS_NO"
										value="<%= class_no %>"
										/>
									<input
										type="hidden"
										name="DELETE_GAKUSEKI_NO"
										value="<%= gakuseki_no %>"
										/>
									<button class="">削除</button>
								</form>
							</th>
						</tr>
					</tbody>
				</table>
          </div>
      </div>
    </div>
  </body>
</html>

```

```java=

// class_update_done2.java
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.HashMap;
import java.util.ArrayList;

public class class_update_done2 extends HttpServlet {
	
	public void doPost (
		HttpServletRequest req,
		HttpServletResponse res )
		throws ServletException , IOException {

		final String URL = "jdbc:mysql://localhost/nhs00157db?useUnicode=true&characterEncoding=UTF-8";
		final String USER = "miyasan";
		final String PASSWORD = "0301";
		final String DRIVER = "com.mysql.jdbc.Driver";

		Connection con = null;
		Statement stmt = null;
		
		HashMap<String,String> map = null;
	    ArrayList<HashMap> list = null;
	    ArrayList<HashMap> _list = null;
	    list = new ArrayList<HashMap>(); // 更新後用配列
	    _list = new ArrayList<HashMap>(); // 更新前用配列

		String class_no,gakuseki_no,syusseki_no,simei_1,simei_2,kana_1,kana_2,umare;
		PrintWriter out;
		req.setCharacterEncoding("UTF-8");
		res.setContentType("text/html;charset=UTF-8");
		out = res.getWriter();
		
		//更新前データ
		String _class_noStr = req.getParameter("_CLASS_NO");
		
		//更新後データ	
		String class_noStr = req.getParameter("CLASS_NO");
		String syusseki_noStr = req.getParameter("SYUSSEKI_NO");
		Integer syusseki_noInt = Integer.parseInt(syusseki_noStr);
		String gakuseki_noStr = req.getParameter("GAKUSEKI_NO");
		String simei_1Str = req.getParameter("SIMEI_1");
		String simei_2Str = req.getParameter("SIMEI_2");
		String kana_1Str = req.getParameter("KANA_1");
		String kana_2Str = req.getParameter("KANA_2");
		String umareStr = req.getParameter("UMARE");
		
		String new_syusseki_noStr = "";

		try {
			Class.forName(DRIVER);
			con = DriverManager.getConnection(URL,USER,PASSWORD);
			stmt = con.createStatement();
			StringBuffer query = new StringBuffer();

			//一件更新
			if(syusseki_noInt < 10){
				new_syusseki_noStr = String.format("%02d", syusseki_noInt);
			} else {
				new_syusseki_noStr = String.valueOf(syusseki_noInt);
			}
			query = new StringBuffer();
			query.append("update class_table set class_no = '");
			query.append(class_noStr);
			query.append("', syusseki_no = '");
			query.append(new_syusseki_noStr);
			query.append("', simei_1 = '");
			query.append(simei_1Str);
			query.append("', simei_2 = '");
			query.append(simei_2Str);
			query.append("', kana_1 = '");
			query.append(kana_1Str);
			query.append("', kana_2 = '");
			query.append(kana_2Str);
			query.append("', umare = '");
			query.append(umareStr);
			query.append("' where gakuseki_no = '");
			query.append(gakuseki_noStr);
			query.append("'");
			stmt.executeUpdate(query.toString());
			
			
			//全件取得（前）	
			query = new StringBuffer();
			query.append("select gakuseki_no from class_table where class_no = '");
			query.append(_class_noStr);
			query.append("' order by kana_1 COLLATE utf8mb4_unicode_ci asc");
			ResultSet rs = stmt.executeQuery(query.toString());
			while (rs.next()) {
				map = new HashMap<String,String>();
	            map.put("gakuseki_no",rs.getString("gakuseki_no"));
	            _list.add(map);
			}
			//全件更新 （前）
			for (int i = 0; i < _list.size(); i++) {
				query = new StringBuffer();
				query.append("update class_table set syusseki_no = '");
				if (i < 10) {
					new_syusseki_noStr = String.format("%02d", i + 1);
					query.append(new_syusseki_noStr);
				} else {
					new_syusseki_noStr = String.valueOf(i + 1);
					query.append(new_syusseki_noStr);
				}
				query.append("' where gakuseki_no = '");
				query.append(_list.get(i).get("gakuseki_no"));
				query.append("'");
				stmt.executeUpdate(query.toString());
			}
			
			//全件取得（後）	
			query = new StringBuffer();
			query.append("select gakuseki_no from class_table where class_no = '");
			query.append(class_noStr);
			query.append("' order by kana_1 COLLATE utf8mb4_unicode_ci asc");
			rs = stmt.executeQuery(query.toString());
			while (rs.next()) {
				map = new HashMap<String,String>();
	            map.put("gakuseki_no",rs.getString("gakuseki_no"));
	            list.add(map);
			}
			
			//全件更新 （後）
			for (int i = 0; i < list.size(); i++) {
				query = new StringBuffer();
				query.append("update class_table set syusseki_no = '");
				if (i < 10) {
					new_syusseki_noStr = String.format("%02d", i + 1);
					query.append(new_syusseki_noStr);
				} else {
					new_syusseki_noStr = String.valueOf(i + 1);
					query.append(new_syusseki_noStr);
				}
				query.append("' where gakuseki_no = '");
				query.append(list.get(i).get("gakuseki_no"));
				query.append("'");
				stmt.executeUpdate(query.toString());
			}


			StringBuffer sb = new StringBuffer();
			sb.append("<html>");
				sb.append("<head>");
					sb.append("<title>名簿更新&クラス並び替え完了</title>");
				sb.append("</head>");
				sb.append("<body>");
					sb.append("<div class=''>");
						sb.append("<div class=''>名簿更新&クラス並び替え</div>");
						sb.append("<div class=''>");
							sb.append("<div class=''>名簿更新&クラス並び替え完了</div>");
							sb.append("<div class=''>");
								sb.append("<a href='/JV27/class_update.html' class=''>更新に戻る</a>");
								sb.append("<a href='/JV27/class_index.html' class=''>ホームに戻る</a>");
							sb.append("</div>");
						sb.append("</div>");
					sb.append("</div>");
				sb.append("</body>");
			sb.append("</html>");
			out.println(sb.toString());
			stmt.close();
			con.close();
		}
		catch (SQLException ex) {
			out.println(" ---- SQL Exception ----");
			out.println(" ---- Error Message ----");
			while (ex != null) {
				out.println(ex.getMessage());
				ex = ex.getNextException();
			}
		} catch (Exception ex) {
			ex.printStackTrace(out);
		}
	}
}

```


<span style="color: #ff3333">aaa</span>
<span style="text-decoration: underline">aaa</span>
## 雑談 (0→やまぴ 1→みや 2→やすい 3→りょうくん 4→アミカ)
おはよう
おはよ
おは