자바/JSP 프로그램 내에서 데이터베이스와 관련된 작업을 처리할 수 있도록 도와주는 자바 표준 인터페이스. 관계형 데이터베이스 시스템에 접근하여 SQL문을 실행하기 위한 자바 API 또는 자바 라이브러리이다.
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.sql.*" %>
<%
Connection conn=null;
try{
String url = "jdbc:mysql://localhost:3306/webmarketDB?serverTimezone=Asia/Seoul&useSSL=false";
String user = "root";
String password = "1234";
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url,user,password);
}catch(SQLException ex){
out.println("데이터베이스 연결이 실패했습니다.");
out.println("SQLException:"+ex.getMessage());
}
%>
PreparedStatement pstmt = null;
String sql = "insert into product values(?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,productId);
pstmt.setString(2,name);
pstmt.setInt(3,price);
pstmt.setString(4,description);
pstmt.setString(5,category);
pstmt.setString(6,manufacturer);
pstmt.setLong(7,stock);
pstmt.setString(8,condition);
pstmt.setString(9,fileName);
pstmt.executeUpdate();
if(pstmt !=null)
pstmt.close();
if(conn !=null)
conn.close();
ResultSet executeQuery(String sql) throws SQLException
ResultSet executeQuery() throws SQLException