Class.forName("org.mariadb.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mariadb://127.0.0.1:3306/db","user","password");
접속한 데이터베이스에 쿼리를 만들때 사용하는 메서드
select
PreparedStatement stmt = conn.prepareStatement("select no, category, title, create_date from board limit 0, 10");
PreparedStatement stmt = conn.prepareStatement("insert into board(category,title,content,create_date) values(?,?,?,curdate())");
stmt.setString(1, category);
stmt.setString(2, title);
stmt.setString(3, content);
ResultSet rs = stmt.executeQuery(); // rs -> 커서
// 다음 데이터행이 없을 때까지 루프를 돌며 처리
while(rs.next()){
rs.getInt("no");
rs.getString("category");
rs.getString("title");
rs.getString("create_date");
}
int row = stmt.executeUpdate(); // int 값 반환, 처리 된 로우의 개수 반환
if(row == 1) {
System.out.println("입력성공");
} else {
System.out.println("입력실패");
}