ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

JS

ajax ๋‘๋ฒˆ์งธ

๐Ÿ”ฅ fire 2010. 7. 13. 20:25

package com.ajax;

import java.sql.*;

public class UserManager {
 public User getUser(String id) {
  User user = null;
 
  try {
   //jdbc 1
   Class.forName("oracle.jdbc.OracleDriver");
   //jdbc 2
   Connection con = DriverManager.getConnection("jdbc:oracle:thin:@211.241.228.11:1521:orcl", "user01", "user01");
   //jdbc 3
   String sql = "select * from member where id = ?";
   //jdbc 4
   PreparedStatement pstmt = con.prepareStatement(sql);
   
   //jdbc 5
   pstmt.setString(1, id);
   
   //jdbc 6
   ResultSet rs = pstmt.executeQuery();
   
   if (rs.next()) {
    //์กฐํšŒ๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ์œผ๋‹ˆ
    user = new User();
    user.setId(rs.getString(1));
    user.setPwd(rs.getString(2));
    user.setName(rs.getString(3));
   }

   //jdbc 7
   rs.close();
   pstmt.close();
   con.close();  
   
  } catch (Exception e) {
   
  }
  return user;
 }
}

๋Œ“๊ธ€