?? typebean.java
字號:
package myBean;
import java.sql.*;
import java.util.*;
import java.io.*;
import myBean.*;
//查看所有的商品分類
public class TypeBean
{
private Connection con;
//公共方法,獲得數據庫的連接
public TypeBean()
{
this.con=DBConnection.getConnection();
}
/**
*返回商品的所有分類,返回的Collection中包含Category值對象。
*/
public Collection getAllType()throws Exception
{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from Types");
Collection ret=new ArrayList();
while(rst.next())
{
Type temp=new Type();
temp.setTypeId(rst.getString("typeId"));
temp.setTypeName(rst.getString("typeName"));
temp.setTypeDescription(rst.getString("typedescription"));
ret.add(temp);
}
//關閉連接,rst和stmt將自動關閉。
con.close();
return ret;
}
/**
*添加一個圖書類別,使用BookType值對象作為參數傳給這個方法。
*/
public void addType(Type type)throws Exception
{
PreparedStatement pstmt=con.prepareStatement("insert into Types values(?,?,?)");
pstmt.setString(1,type.getTypeId());
pstmt.setString(2,type.getTypeName());
pstmt.setString(3,type.getTypeDescription());
pstmt.execute();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -