viewcategory.java

来自「基于WEB的商品管理系统」· Java 代码 · 共 51 行

JAVA
51
字号
/*
 * ViewCategory.java
 *
 * Created on 2007年10月25日, 下午3:37
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.me.product;

import java.sql.*;
import java.util.*;
import java.io.*;
import org.me.util.*;

/**
 *
 * //查看所有的商品分类
 */
public class ViewCategory {
    
    /** Creates a new instance of ViewCategory */
   private Connection con;
	//公共方法,获得数据库的连接
	public ViewCategory()
	{
		this.con=DataBaseConnection.getConnection();
	}
	/**
	 *返回商品的所有分类,返回的Collection中包含Category值对象。
	 */
	public Collection getAllCategory()throws Exception
	{
		Statement stmt=con.createStatement();
		ResultSet rst=stmt.executeQuery("select * from category");
		Collection ret=new ArrayList();
		while(rst.next())
		{
			Category temp=new Category();
			temp.setCategoryId(rst.getString("catid"));
			temp.setDescription(rst.getString("descn"));
			temp.setName(rst.getString("name"));
			ret.add(temp);
		}
		//关闭连接,rst和stmt将自动关闭。
		con.close();
		return ret;
	}
}

⌨️ 快捷键说明

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