⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 allitemaccess.java

📁 Athena酒店小组_Athena酒店管理系统
💻 JAVA
字号:
/*
 * AllItemAccess.java
 *
 * Created on 2007年6月19日, 下午9:24
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jimmie;

import java.util.*;
import java.sql.*;

import plugin.*;
/**
 *
 * @author Jimmie
 */
public class AllItemAccess {
    private IDBResource dbRes;
    /** Creates a new instance of BookAccess */
    public AllItemAccess(IDBResource dbRes) 
    {
        this.dbRes=dbRes;
    }
    
     public int insert(AllItem all)
    {
	try
	{
	    Connection conn = dbRes.getConnection();
	    String sql = "INSERT INTO AllItem(ItemNum,ItemName,Unit,Price) " +
		    " VALUES(?, ?,?,?)";
	    PreparedStatement ps = conn.prepareStatement(sql);
	    ps.setString(1, all.getItemNum());
	    ps.setString(2,all.getItemName());
            ps.setString(3,all.getUnit());
            ps.setFloat(4,all.getPrice());
	    int rs = ps.executeUpdate();	    
	    return rs;
	}
	catch (SQLException ex)
	{
	    ex.printStackTrace();
	    return -1;
	}
     }


    public ArrayList<AllItem> getAllItems()
    {
	try
	{
	    Connection conn = dbRes.getConnection();
	    String sql = "SELECT * FROM AllItem";
	    PreparedStatement ps = conn.prepareStatement(sql);
	    ResultSet rs = ps.executeQuery();
	    ArrayList<AllItem> items = new ArrayList<AllItem>();
	    while(rs.next())
	    {
		AllItem item = new AllItem();
		item.setItemNum(rs.getString("ItemNum"));
		item.setItemName(rs.getString("ItemName"));
		item.setUnit(rs.getString("Unit"));
                item.setPrice(rs.getFloat("Price"));
                items.add(item);
	    }
	    return items;
	}
	catch (SQLException ex)
	{
	    ex.printStackTrace();
	    return null;
	}		
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -