본문 바로가기

개발/jsp

DB이용한 입출력하기2

<입력폼에 값 입력후 DB저장 처리후 출력하기 소스 #2>

 

:: list_write.jsp(값입력) -> exequery.jsp(쿼리실행) -> list_output.jsp(DB출력)

   dbconn.jsp(DB연결시켜줌), _tail.jsp(DB연결해제함)

   *주의* DB저장과 DB출력은 서로 다른페이지로 구현한다.

 

 

==============================================

dbconn.jsp

 

<%@page contentType="text/html;charset=euc-kr"%>
<%
 String user="root";
 String pass="1";
 String dbURL = "jdbc:mysql://localhost/db_test";
 Statement stmt=null; 
 Connection conn=null;
 ResultSet rs=null;   
 
 try{ 
  Class.forName("com.mysql.jdbc.Driver");
 }catch(ClassNotFoundException cnfe){
  System.out.println("Cannot Find Driver!!!!");
  cnfe.toString();
 }
 
 conn=DriverManager.getConnection(dbURL,user,pass);
 out.println("2-Driver Connection Success"+"<br>");
 
 stmt = conn.createStatement(); 
%>

 

==============================================

_tail.jsp

 

<% 

    if ( rs != null ){
        rs.close();
        rs = null;
    }
    if ( stmt != null ){
        stmt.close();
        stmt = null;
    }
    if ( conn != null ){
        conn.close();
        conn = null;
    }
%>

==============================================

 

:: 입력폼 과 DB출력

 

'개발 > jsp' 카테고리의 다른 글

게시판 - 페이지사이즈를 이용한 for문 돌리기  (0) 2020.02.05
textarea 전송  (0) 2020.02.05
DB이용한 입출력하기  (0) 2020.02.05
답변형 게시판 JSP 관계도  (0) 2020.02.05
날짜비교 후 이미지 보이기  (0) 2020.02.05