달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

'JSP'에 해당되는 글 3

  1. 2009.05.19 [JSP] PreparedStatement
  2. 2009.05.14 JSP 몇가지
  3. 2009.05.12 JSP 한글처리
2009. 5. 19. 08:38

[JSP] PreparedStatement 메모2009. 5. 19. 08:38

JSP에서 쿼리문을 사용할 때 PreparedStatement를 사용하는 방법.

1. 객체생성
PreparedStatement pStmt = connect.prepareStateme("select id, name from table where id = ?");

2. ? 에 값 지정
setInt(1, id_value)
or
setString(1, id_value)

3. 실행
ResultSet rs = pStmt.executeQuery();
pStmt.close();
:
Posted by 하늘바램
2009. 5. 14. 09:03

JSP 몇가지 메모2009. 5. 14. 09:03

1. setProperty
JSP 페이지의 파라미터 이름과 자바빈 프로퍼티의 이름을 같게하면 다음과 같은 한 줄로 모든 파라미터를 한꺼번에 저장할 수 있다.
<jsp:setProperty property="*" name="BeanName" />

2. JSP의 DB 연결 순서.
- JDBC 드라이버 로드
    Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection 생성
    Connection con = DriverManager.getConnection(url, uid, pwd);
    (oracle url : jdbc:oracle:thin:@localhost:1521:ORCL
     mysql url  : jdbc:mysql://localhost:3306/jdbc
     ms-sql url: jdbc:microsoft:sqlserver://localhost:1433)
- Statement 객체생성
    Statement st = con.createStatement();
- SQL 문 실행처리
    ResultSet rs = st.executeQuery("select * from table");
    (update, insert, delete 등의 쿼리문을 실행할 때는 executeUpdate 메소드를 사용한다)

3. ResultSet 값을 가져올때 컬럼명을 사용하는 것보다 인덱스번호를 사용하는 것이 속도면에서 더 빠르다. 하지만 소스가독성면에서는 현저히 떨어지기 때문에 주의해야 한다.
4. JSP에서 선언부( <%! ~ %> )는 첫 방문자에 의해서 단 한번만 수행된다.
5. <%~%> : 요걸 '스크립트릿(Scriptlet)' 이라고 부른다.
:
Posted by 하늘바램
2009. 5. 12. 08:32

JSP 한글처리 메모2009. 5. 12. 08:32

1. 웹페이지 :  지시자에서 캐릭터 셋을 euc-kr로 지정.
<%@ page language="java" contentType="text/html;charset=euc-kr">

2. post 방식 :  request 객체의 인코딩 방식을 euc-kr로 변경.
<% request.setCharacterEncoding("euc-kr") %>

3. get 방식 : String 클래스의 getBytes 메소드를 사용.

    수신시 : 영문을 한글로 변환(8859_1 -> euc-kr)
 String s_name = request.getParameter("name");
 s_name = new String(s_name.getBytes("8859_1"), "euc-kr");

    전달시 : 한글을 영문으로 변환(euc-kr -> 8859_1)
 String s_name = "한글변환";
 s_name = new String(s_name.getBytes("euc-kr"), "8859_1");
:
Posted by 하늘바램