Code example for PreparedStatement

Methods: close, executeUpdate, setString, setTimestamp

0
	 
	public void addArticle(Article article) throws SQLException{
		Connection conn = Conn.getConnection();
		String sql = "INSERT INTO  article (username,date_time,title,cons) values (?,?,?,?)";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, article.getUsername());
		pstmt.setTimestamp(2,new Timestamp(System.currentTimeMillis()));
		pstmt.setString(3, article.getTitle());
		pstmt.setString(4,article.getCons());
		pstmt.executeUpdate();
		pstmt.close();
		conn.close();
	} 
 
	public ArrayList<Article> query_art_all() {
		ArrayList<Article> list = new ArrayList<Article>();
		Connection conn;
		try { 
			conn = Conn.getConnection();
			String sql = "select * from article order by id desc limit 1,6";
			PreparedStatement pstmt = conn.prepareStatement(sql);