<%@page import="java.sql.*"%>

<%@page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%

  String newid = request.getParameter("id");

  String newpasswd = request.getParameter("passwd");

  String newname = request.getParameter("name");

  Timestamp newregdate = new Timestamp(System.currentTimeMillis()); 

 %>

<!DOCTYPE html>

<html>

<head>

<meta charset="EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%

Connection conn = null;

PreparedStatement pstmt = null;

ResultSet rs = null;

try{

String jdbcUrl = "jdbc:mysql://localhost:3306/basicjsp";

String dbid = "jspid";

String dbpasswd = "jsppass";

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection(jdbcUrl,dbid,dbpasswd);

String sql = "insert into member values(?,?,?,?)";

pstmt = conn.prepareStatement(sql);

pstmt.setString(1,newid);

pstmt.setString(2,newpasswd);

pstmt.setString(3,newname);

pstmt.setTimestamp(4,newregdate);

pstmt.executeUpdate();

pstmt.close();

String sql2 = "select * from member";

pstmt = conn.prepareStatement(sql2);

rs = pstmt.executeQuery();

%>

<table>

<% while(rs.next()){

String id = rs.getString("id");

String passwd = rs.getString("passwd");

String name = rs.getString("name");

Timestamp reg_date = rs.getTimestamp("reg_date");

%>

<tr>

<td><%=id %></td>

<td><%=passwd%></td>

<td><%=name%></td>

<td><%=reg_date%></td>

</tr>

<%}

}catch(Exception e){

e.printStackTrace();

}finally{

if(rs!=null){

rs.close();

}

if(conn!=null){

conn.close();

}

if(pstmt!=null){

pstmt.close();

}

}%>

</table>

</body>

</html>

member 테이블에 받은 파라미터 값으로 insert 를 한 다음에

Preparedstatement를 닫아주는게 맞나요?

일단 원하던 결괏값은 얻었는데

한 파일 내에서 두개의 sql 문장을 쓸려면 저렇게 하는게 맞나여

include를 해야하나