statementTest.jsp
페이지 정보
본문
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="java.sql.*"%>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
String user="root";
String password="1111";
Connection conn = null;
Statement stmt = null;
String sql="INSERT INTO student (num,name) VALUES (7,'홍길동')";
try {
conn=DriverManager.getConnection(url, user, password);
stmt=conn.createStatement();
int result=stmt.executeUpdate(sql);
if(result!=0){
out.println("<h3>레코드가 등록되었습니다.</h3>");
}
}catch(Exception e){
out.println("<h3>레코드 등록에 실패하였습니다.</h3>");
e.printStackTrace();
}
finally{
try{
stmt.close();
conn.close();
}
catch(Exception e){
e.printStackTrace();
}
}
%>
- 이전글● Statement 와 PreparedStatement 21.07.15
- 다음글preparedStatementTest.jsp 21.07.15
댓글목록
등록된 댓글이 없습니다.