Code example for PreparedStatement

Methods: executeUpdate, setString, setTimestamp

0
		Connection conn = JDBCUtilsSingleton.getInstance().getConnection();
		// create statement 
		PreparedStatement ps = conn
				.prepareStatement("insert into student(name,birthday) values(?,?)");
		// execute query 
		ps.setString(1, name);
		ps.setTimestamp(2, new java.sql.Timestamp(birthday.getTime()));
		// ps.setDate(2, new java.sql.Date(birthday.getTime())); 
		int i = ps.executeUpdate();
		System.out.println(i);
		JDBCUtilsSingleton.getInstance().close(null, ps, conn);
	} 
 
	private static void read(int id) throws SQLException {
		// get connection 
		Connection conn = JDBCUtilsSingleton.getInstance().getConnection();
		// create statement 
		PreparedStatement ps = conn
				.prepareStatement("select birthday from student where id=?");
		// execute query 
		ps.setInt(1, id);