특별한딸기이야기

서버 접속 참고 녀석 본문

딸기 공부방/웹프로그래밍

서버 접속 참고 녀석

특별한녀석 2008. 5. 25. 23:45
<%@ page contentType = "text/html;charset=euc-kr" %>
<%@ page import = "java.sql.*" %>
<html>
 <head>
  <title>
   테이블의 레코드를 화면에 표시하는 예제
  </title>
 </head>
 <body>
  <h2>
   member1 테이블의 레코드를 화면에 표시하는 예제
  </h2>
  <table width = "550" border = "1">
   <tr>
    <td width = "100">
     아이디
    </td>
    <td width = "100">
     패스워드
    </td>
    <td width = "100">
     이름
    </td>
    <td width = "250">
     가입일자
    </td>
   </tr>
   <%
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
   
    try
    {
     Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
     con = DriverManager.getConnection("jdbc:sqlserver://ants.mju.ac.kr:1433", "webp_32", "a123a123");
     
     String sql = "select * from Table_1";
     
     pstmt = con.prepareStatement(sql);
     rs = pstmt.executeQuery();
     
     while(rs.next())
     {
      String id = rs.getString("ID");
      String pw = rs.getString("PW");
      String name = rs.getString("Name");
   %>
    <tr>
     <td width = "100">
      <%= id%>
     </td>
     <td width = "100">
      <%= pw%>
     </td>
     <td width = "100">
      <%= name%>
     </td>
    </tr>
   <%
     }
    }
    catch(Exception e)
    {
     e.printStackTrace();
    }
    finally
    {
     if(rs != null)
     {
      try
      {
       rs.close();
      }
      catch(SQLException sqle)
      {
      }
     }
     if(pstmt != null)
     {
      try
      {
       pstmt.close();
      }
      catch(SQLException sqle)
      {
      }
     }
     if(con != null)
     {
      try
      {
       con.close();
      }
      catch(SQLException sqle)
      {
      }
     }
    }
   %>
  </table>
 </body>
</html>