📄 getdatabean.java
字号:
package com.lyh.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.lyh.entity.*;
import com.lyh.common.*;
public class GetDataBean {
private Connection connection;
private PreparedStatement foodsQuery;
private ResultSet results;
public ArrayList<FoodBean> getFoods()
{
ArrayList<FoodBean> foodsList=new ArrayList<FoodBean>();
try
{
connection=DBConnection.getConnection();
foodsQuery=connection.prepareStatement("select * from foodInfo Order by foodID");
results=foodsQuery.executeQuery();
while(results.next())
{
FoodBean food=new FoodBean();
food.setFoodID(results.getString("foodID"));
food.setFoodName(results.getString("foodName"));
food.setRemark(results.getString("Remark"));
food.setFoodPrice(results.getDouble("foodPrice"));
food.setDescription(results.getString("Description"));
food.setFoodImage(results.getString("foodImage"));
foodsList.add(food);
}
}catch(SQLException ex)
{
System.out.print(ex.getMessage());
}
finally
{
DBConnection.closeConnection(connection);
DBConnection.closeStatement(foodsQuery);
DBConnection.closeResultSet(results);
}
return foodsList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -