business.setBusinessId(rs.getInt("businessId"));
时间: 2024-04-24 18:27:29 浏览: 24
这段代码是在Java中使用SQL语句更新数据库中的商家信息。\[1\]其中的问号是占位符,表示需要传入的参数。通过设置参数的方式,可以更新商家的名称、地址、说明、起送价和配送费用。\[1\]在这段代码中,通过rs.getInt("businessId")获取到了数据库中的商家ID,并将其设置到Business对象的businessId属性中。这样可以将数据库中的商家ID与Java对象进行关联。
#### 引用[.reference_title]
- *1* *2* *3* [实训-3-Java控制台版外卖管理系统](https://blog.csdn.net/weixin_29538497/article/details/114665682)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关问题
intent.getextras().getint
Intent.getExtras().getInt()是一种用于从Intent对象的附加数据中获取整数值的方法。当我们在一个Activity中使用Intent来启动另一个Activity时,我们可以通过Intent对象的getExtras()方法来获取传递的附加数据。一旦我们获取到了Bundle对象,就可以使用getInt()方法来获取具体的整数值。
举个例子,假设我们在Activity A中使用Intent来启动Activity B,并且在Intent中添加了一个整数值作为附加数据。在Activity B中,我们可以通过以下方式获取这个整数值:
Intent intent = getIntent(); // 获取启动Activity B的Intent对象
Bundle extras = intent.getExtras(); // 获取附加数据的Bundle对象
int value = extras.getInt("key"); // 通过key从Bundle中获取整数值
在上面的代码中,"key"是我们在Activity A中使用Intent.putExtra()方法添加附加数据时所使用的键。我们可以自定义这个键值对,来传递任何整数值给Activity B。
使用Intent.getExtras().getInt()方法,我们可以轻松地获取附加数据中的整数值,并进行后续的处理和操作。
public Food findFoodById(int foodId) { String sql="select * from food where foodId=?"; Connection conn=DBUtil.getConnection(); PreparedStatement ps=null; ResultSet res=null; List<Food> foodList1 = new ArrayList<Food>(); try { ps=conn.prepareStatement(sql); ps.setInt(1, foodId); res=ps.executeQuery(); while(res.next()) { Food food=new Food(); food.setBusinessId(res.getInt("foodId")); food.setFoodExplain(res.getString("foodExplain")); food.setFoodId(res.getInt("foodId")); food.setFoodName(res.getString("foodNamd")); food.setFoodPrice(res.getDouble("foodPrice")); foodList1.add(food); } } catch (SQLException e) { e.printStackTrace(); }finally { DBUtil.close2(ps); DBUtil.close1(conn); } return ; } 有什么错误
这段代码中存在一个问题:在最后的 return 语中没有返回任何值应该返回查询到 Food 对象或者 null,具体应该根据查询结果是否为空来决定。可以将最后的 return 语句修改为以下代码:
```
return foodList1.isEmpty() ? null : foodList1.get(0);
```
另外,代码中设置了两次 businessId 属性,第一次应该是设置 foodId 属性,可以将其修改为以下代码:
```
food.setFoodId(res.getInt("foodId"));
```
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)