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

📄 loadproducts.java

📁 这是一个网上卖衣服的网站项目
💻 JAVA
字号:

/*************************************************
 *
 *从数据库中装载一批产品
 *
 **************************************************/
 
 package mylib;
 
 public class LoadProducts {
 	
 	private LoadProducts() {
 		 
 	}
	
	/*从数据库装载tb_Product表中所有纪录*/
	public Product[] load() throws Exception {
		
		
		
		ConnectionDB condb = new ConnectionDB();
		String sqlstr = "Select * from tb_Product";
		java.sql.ResultSet rs = condb.executeQuery(sqlstr,java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
		
		rs.last();//指向最后一行以获得改结果集的总纪录数
		Product[] products = new Product[rs.getRow()];
		
		rs.beforeFirst();//指向第一行之前
		int i = 0;
		while(rs.next()) {
			
			String isdn = rs.getString("ISDN");
			String name = rs.getString("Product_Name");
			String sexType = rs.getString("SexType");
			String category = rs.getString("Category");
			String brand = rs.getString("Brand");
			String size = rs.getString("Product_Size");
			java.sql.Date date = rs.getDate("Stock_Date");
			double price = rs.getDouble("Price");
			double costPrice = rs.getDouble("CostPrice");
			int stock = rs.getInt("Stock");
			int commend = rs.getInt("Commend");
			
			javax.swing.ImageIcon[] images = {new javax.swing.ImageIcon(rs.getBytes("Image1")),
												new javax.swing.ImageIcon(rs.getBytes("Image2"))};
												
			products[i++] = new Product(isdn,name,
										sexType,category,
										brand,size,
										date,price,
										costPrice,stock,
										commend,images);
		}
		
		rs.close();
		condb.close();
		
		return products;
	} 	



 	/*获取LoadProducts的一个唯一实例*/
 	public static LoadProducts getInstance() {
 		return lp;
 	}
 	
 	private static LoadProducts lp = new LoadProducts();
 	 	
 	
 	
 	
 	
 	
 	/*****************************************
 	 *测试main()
 	 *****************************************/
 	 public static void main(String[] args) {
 	 	Product[] pros = null;
 	 	try {
 	 		pros = LoadProducts.getInstance().load();
 	 	}
 	 	catch(Exception ex) {
 	 		ex.printStackTrace();
 	 	}
 	 	
 	 	javax.swing.ImageIcon[] icon = pros[0].getImages();
		
		
		for(int i=0;i<icon.length;i++) {
			javax.swing.JFrame f = new javax.swing.JFrame();
			javax.swing.JPanel pan = new javax.swing.JPanel();
			javax.swing.JLabel lbl = new javax.swing.JLabel();
			System.out.println(icon[i]);
			lbl.setIcon(icon[i]);
			pan.add(lbl);
			f.setContentPane(pan);
			f.setSize(200,200);
			f.setVisible(true);
		}
 	 }
 }

⌨️ 快捷键说明

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