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출력