请看下面的javabean程序,望赐教!万分感谢。

inzaghizxy 2001-11-19 12:04:53
我写了三个javabean,但是编译说有错误,我还不知如何修改,望各位
指点。给分.

1.(1个错误,程序中有提示//error)
package Bean;
import java.sql.*;
import java.util.*;
import java.lang.Exception;

public class CCategoryBean {
int id; //The category ID
String name; //The category name
int count; //Total number of magazines in a category
String magazineList[]; //A list of all magazines in the category
public CCategoryBean() {
}
public void UpdateProductList(int id){
try
{
Class.forName("sun.jdbc.db2.JdbcDb2Driver");
String url = "jdbc:db2:cp1897";
Connection con=DriverManager.getConnection(url,"username","password");
String query="select * from CPMAGMASTER where MGCATNBR = this.id";
Statement statement=con.createStatement();
ResultSet result=statement.executeQuery(query);

public int getid(){ //error(编译时此处有错误)
return result.getInt("MGCATNBR");
}
public void setid(int id){
if(id != this.id){
this.id=id;
this.UpdateProductList();
}
else{
this.UpdateProductList();
}
}
public String getname(){

Hashtable CAT = new Hashtable();
CAT.put(new Integer(100), "報紙--每日寄發");
CAT.put(new Integer(102), "報紙--合訂本或索引");
CAT.put(new Integer(103), "報紙--每月寄發二次(日報與周六報按月訂閱,其他報紙按季訂閱)");
CAT.put(new Integer(104), "綜合性畫報");
CAT.put(new Integer(105), "旅遊.娛樂.體育.生活");
CAT.put(new Integer(106), "文化.知識");
CAT.put(new Integer(107), "哲學.社會科學");
CAT.put(new Integer(108), "大專院校學報(哲學.社科版)");
CAT.put(new Integer(109), "政治.經濟.法律.時事");
CAT.put(new Integer(110), "教育");
CAT.put(new Integer(111), "歷史.地理.文物.考古");
CAT.put(new Integer(112), "老年.青年.婦女.少年.兒童");
CAT.put(new Integer(113), "文學");
CAT.put(new Integer(114), "電影.戲劇");
CAT.put(new Integer(115), "音樂.舞蹈");
CAT.put(new Integer(116), "美術.書法.攝影.其他");
CAT.put(new Integer(117), "科學普及知識");
CAT.put(new Integer(118), "自然科學");
CAT.put(new Integer(119), "大專院校學報(自然科學版)");
CAT.put(new Integer(120), "數學.物理.化學");
CAT.put(new Integer(121), "天文.地質.海洋");
CAT.put(new Integer(122), "生物科學");
CAT.put(new Integer(123), "農林.畜牧.海洋");
CAT.put(new Integer(124), "工程技術");
CAT.put(new Integer(125), "電子");
CAT.put(new Integer(126), "能源化工");
CAT.put(new Integer(127), "計算機儀器儀表");
CAT.put(new Integer(128), "建築");
CAT.put(new Integer(129), "機械");
CAT.put(new Integer(130), "西醫學");
CAT.put(new Integer(131), "醫科大學學報");
CAT.put(new Integer(132), "中醫藥");
CAT.put(new Integer(133), "西藥");
CAT.put(new Integer(134), "和平圖書有限公司代理品種");
CAT.put(new Integer(135), "複印報刊資料");
CAT.put(new Integer(201), "精選推介──中醫");
CAT.put(new Integer(202), "精選推介──文化.知識");
CAT.put(new Integer(203), "精選推介──文學");
CAT.put(new Integer(204), "精選推介──政治");
CAT.put(new Integer(205), "精選推介──經濟");
CAT.put(new Integer(206), "精選推介──歷史.考古");
CAT.put(new Integer(207), "精選推介──音樂");
CAT.put(new Integer(208), "精選推介──旅遊.生活");
name = (String)CAT.get(this.id);
return name;
}
while(result.next())
{
public int getcount(){
if (result.last() == true){
return result.getInt("MGRFNBR");
}
}
public String[] getmagazineList(){
for (int i=1;i<=count ;i++ ){
magazineList[] = result.getString(i);
}
return magazineList[];
}
result.close();
statement.close();
connection.close();
};
}

catch(Exception e)
{
System.out.println(e.toString());
}
}
}


2.(2个错误,程序中有提示//error)
package Bean;
import java.sql.*;
import java.util.*;
import java.lang.Exception;

public class CMagazineBean {
String id; //The magazine code
String name; //The magazine name
boolean remark; //true if the magazine has remark
String publisher; //The publisher of the magazine
String issue; //The magazine issue frequency
float charge1; //The charge of the magazine for Hong Kong only.
float charge2; //The charge of the magazine for China, Macao and Taiwan
float charge3; //The charge of the magazine for Oversea
float charge4; //The charge of the magazine with air mailing charge Type I
float charge5; //The charge of the magazine with air mailing charge Type II
String cover; //The filename of the cover image
String desc; //The description of the magazine
public CMagazineBean() {
}
public void findByPrimaryKey(int id){
try
{
Class.forName("sun.jdbc.db2.JdbcDb2Driver");
String url = "jdbc:db2:cp1897";
Connection con=DriverManager.getConnection(url,"username","password");
String query="select * from CPMAGMASTER where MGRFNBR = id";
Statement statement=con.createStatement();
ResultSet result=statement.executeQuery(query);
public String getid(){ //error(编译时此处有错误)
return result.getString("MGBKNBR");
}
public String getname(){
return result.getString("MGBKNAME");
}
public boolean getremark(){
return result.getBoolean("MGREMARK");
}
public String getpublisher(){
return result.getString("MGPUBLISH");
}
public String getissue(){
return result.getString("MGFREQ");
}
public float getcharge1(){
return result.getFloat("MGMAILCR1");
}
public float getcharge2(){
return result.getFloat("MGMAILCR2");
}
public float getcharge3(){
return result.getFloat("MGMAILCR3");
}
public float getcharge4(){
return result.getFloat("MGMAILCR4");
}
public float getcharge5(){
return result.getFloat("MGMAILCR5");
}
public String getcover(){
return result.getString("MGBKCOVER");
}
public String getdesc(){
return result.getString("MGDESC");
}

result.close();
statement.close();
connection.close(); //error(编译时此处有错误)
}
catch(Exception e)
{
System.out.println(e.toString());
}
}

}


3.(2个错误,程序中有提示//error)
package Bean;
import java.sql.*;
import java.util.*;
import java.lang.Exception;

public class CCartBean {
try //error(编译时此处有错误)
{
boolean empty; //true if the cart is empty, false otherwise
float total; //The total price for all magazines in the cart
int[] magID; //magazine primary keys
int[] mail; //mailing methods of the order
int[] qty; //quantities of the order
float price[]; //the price of the magazine
Hashtable magazineList = new Hashtable();//A list of all magazines in the cart
public CCartBean() {
for (int i=0;i<magID.length ; i++)
{
magazineList.put(magID(i),(qty(i),mail(i)));
}
}
public boolean getEmpty(){
return this.empty;
}
public int[] getMagID(){
return this.magID;
}
public int[] getMail(){
return this.mail;
}
public int[] getQty(){
return this.qty;
}
public float[] getPrice(){
return this.price;
}
public void addMagazine(int magID,int mail,int qty){
magazineList.put(magID,(qty,mail));
}
public void removeMagazine(int magID){
if (!empty)
{
magazineList.remove(magID);
}
}
public void modifyQty(int magID,int qty){
Vector maga=new Vector();
if (!empty)
{
maga=magazineList.get(magID);
magazineList.put(magID,(maga.set(0,qty)));
}
}


public float getTotal(){
float total=0.00;
String s;
for (int num=0;num<qty.length ;num++ )
if (!s.valueOf(qty[num]).trim().equals("")){
int quans=qty[num];
if (quans>0){
total += quans*price[num];
}
}
return total;
}
}
catch(NullPointerException e)
{
String err=e.toString();
System.out.println(err);
}
catch(ArrayIndexOutOfBoundsException e)
{
String err=e.toString();
System.out.println(err);
}
catch(IllegalArgumentException e)
{
String err=e.toString();
System.out.println(err);
} //error(编译时此处有错误)


}



希望各位大虾帮我改正这几点错误,多谢送分!
...全文
77 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmvigour 2001-11-19
  • 打赏
  • 举报
回复
1.public int getid(){ //error(编译时此处有错误)
return result.getInt("MGCATNBR");
}
这里的result不是全局变量,你应声明一个为result的类成员变量,或者把resultset类型的变量作为参数传进来,
我觉得你还是好好看一下书本把!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧