resultSetTest.jsp
페이지 정보
본문
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="java.sql.*"%>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
String user="root";
String password="1111";
Connection conn = null;
PreparedStatement pstmt= null;
ResultSet rs=null;
String sql="SELECT * FROM student";
try {
conn=DriverManager.getConnection(url, user, password);
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()){
out.println("<h3>"+rs.getInt(1)+","+rs.getString(2)+"</h3>");
}
}catch(Exception e){
out.println("<h3>데이터 가져오기에 실패하였습니다.</h3>");
e.printStackTrace();
}finally{
try{
rs.close();
pstmt.close();
conn.close();
}
catch(Exception e){
e.printStackTrace();
}
}
%>
- 이전글● ResultSet 21.07.15
- 다음글● Statement 와 PreparedStatement 21.07.15
댓글목록
등록된 댓글이 없습니다.