Code example for PreparedStatement

Methods: executeUpdate, setFloat, setInt, setString

0
 
		try { 
			conn = DButil2.getConnection();
			pstmt = DButil2.getPreparedStatement(conn, sql);
 
			pstmt.setString(1, foods.getFoodName());
			pstmt.setFloat(2, foods.getFoodPrice());
			pstmt.setInt(3, foods.getFoodType());
			pstmt.setString(4, foods.getFoodDescri());
			pstmt.setString(5, foods.getFoodImage());
			 
			pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		return 0; 
	} 
 
	//Ìí¼Ó¶©µ¥Óû§µÄÐÅÏ¢¡£µ«ÊÇÒª·µ»ØorderId,ÒÔ±ãÉÔºó²åÈëµ½ÁíÍâÒ»ÕűíÖе±Íâ¼ü¡£ 
	public int addOrder(OrderFoods order) {//Ìí¼Ó¶©µ¥£¬Î´Íê³É£¬ÓдýÌÖÂÛ£¨¹ØÓÚÓû§IDµÄÎÊÌ⣩
		Connection conn=null;