请大侠们帮忙看看我的问题:构造函数问题,谢了!

yellowpage3403 2005-10-17 10:18:04
编译时报错如下:
C:\Tomcat 5.5\webapps\lsgl\lend\WEB-INF\classes>javac -d . DB.java
DB.java:70: 找不到符号
符号: 构造函数 Goods(int,java.lang.String,java.lang.String,int,java.lang.String
,int,int,float,float,java.lang.String,java.lang.String,int,java.sql.Date,int)
位置: 类 lend.Goods
Goods gd=new Goods(
^
DB.java:113: 找不到符号
符号: 构造函数 Goods(int,java.lang.String,java.lang.String,int,java.lang.String
,int,int,float,float,java.lang.String,java.lang.String,int,java.sql.Date,int)
位置: 类 lend.Goods
Goods gd=new Goods(
^
注意: DB.java 使用了未经检查或不安全的操作。
注意: 要了解详细信息,请使用 -Xlint:unchecked 重新编译。
2 错误

下面是程序:
请问错在哪里了?
=================================================================================
Goods.java

======================================================
package lend;
import java.util.Date;
import java.io.*;
import java.math.*;

public class Goods
{
//属性

private int goodsId=0;
private String code=null;
private String name=null;
private int kind=0;
private String memoryCode=null;
private String barCode=null;
private String unit=null;
private int qty=0;
private int onHand=0;
private double price=0.0;
private double rent=0.0;
private String description=null;
private String publisher=null;
private int country=0;
private Date publishDate=new java.util.Date();
private int closed=0;



public Goods(int goodsId,String code,String name,int kind,String memoryCode,
String barCode,String unit,int qty,int onHand,double price,double rent,
String description,String publisher,int Country,Date publishDate,int closed)
{
this.goodsId=goodsId;
this.code=code;
this.name=name;
this.kind=kind;
this.unit=unit;
this.qty=qty;
this.onHand=onHand;
this.price=price;
this.rent=rent;
this.description=description;
this.publisher=publisher;
this.country=country;
this.publishDate=publishDate;
this.closed=closed;
}
//getter方法
public int getGoodsId()
{
return this.goodsId;
}
.............
}


DB.java
=======================================================================
package lend;

import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
import java.util.*;
import lend.*;

public class DB {
private ArrayList goods;
private DataSource ds=null;

public DB()throws Exception
{
Context initCtx = new javax.naming.InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource)envCtx.lookup("lsgl");
}

public Connection getConnection() throws Exception
{
return ds.getConnection();
}
public void closeConnection(Connection con)
{
try{
if (con!=null)
con.close();
} catch(Exception e){
e.printStackTrace();
}
}

public void closePrepStmt(PreparedStatement pstmt)
{
try{
if (pstmt!=null)
pstmt.close();
}catch(Exception e){
e.printStackTrace();
}
}
public void closeResultSet(ResultSet rs)
{
try{
if (rs!=null)
rs.close();
}catch(Exception e){
e.printStackTrace();
}
}


public Collection getGoods() throws Exception
{
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
goods=new ArrayList();
try{
con=getConnection();
String str="select * from goods";
pstmt=con.prepareStatement(str);
rs=pstmt.executeQuery();
while (rs.next())
{
Goods gd=new Goods(
rs.getInt("goodsId"),
rs.getString("code"),
rs.getString("name"),
rs.getInt("kind"),
rs.getString("unit"),
rs.getInt("qty"),
rs.getInt("onHand"),
rs.getFloat("price"),
rs.getFloat("rent"),
rs.getString("description"),
rs.getString("publisher"),
rs.getInt("country"),
rs.getDate("publishDate"),
rs.getInt("closed") );
goods.add(gd) ;
}

}finally{
closeResultSet(rs);
closePrepStmt(pstmt);
closeConnection(con);
}
Collections.sort(goods) ;
return goods;
}


public Goods getGoodsDetails(int goodsId) throws Exception
{
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
goods=new ArrayList();
try{
con=getConnection();
String str="select * from goods where goodsid=?";

pstmt=con.prepareStatement(str);
pstmt.setInt(1,goodsId);
rs=pstmt.executeQuery();
if (rs.next())
{
Goods gd=new Goods(
rs.getInt("goodsId"),
rs.getString("code"),
rs.getString("name"),
rs.getInt("kind"),
rs.getString("unit"),
rs.getInt("qty"),
rs.getInt("onHand"),
rs.getFloat("price"),
rs.getFloat("rent"),
rs.getString("description"),
rs.getString("publisher"),
rs.getInt("country"),
rs.getDate("publishDate"),
rs.getInt("closed"));
//goods.add(gd) ;
pstmt.close();
return gd;
}
else
{return null;}

}finally{
closeResultSet(rs);
closePrepStmt(pstmt);
closeConnection(con);
}

}
}
...全文
196 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yellowpage3403 2005-10-17
  • 打赏
  • 举报
回复
谢谢interhanchi(Stallman'fans) ,是参数的个数问题!
请问:
注意: DB.java 使用了未经检查或不安全的操作。
注意: 要了解详细信息,请使用 -Xlint:unchecked 重新编译。
这是什么原因呢?
interhanchi 2005-10-17
  • 打赏
  • 举报
回复
仔细看一下你的构造函数的参数。
public Goods(int goodsId,String code,String name,int kind,String memoryCode,
String barCode,String unit,int qty,int onHand,double price,double rent,
String description,String publisher,int Country,Date publishDate,int closed)

Goods gd=new Goods(
rs.getInt("goodsId"),
rs.getString("code"),
rs.getString("name"),
rs.getInt("kind"),
rs.getString("unit"),
rs.getInt("qty"),
rs.getInt("onHand"),
rs.getFloat("price"),
rs.getFloat("rent"),
rs.getString("description"),
rs.getString("publisher"),
rs.getInt("country"),
rs.getDate("publishDate"),
rs.getInt("closed") );
参数匹配吗?

superslash 2005-10-17
  • 打赏
  • 举报
回复
报什么错,贴出来大家看
yellowpage3403 2005-10-17
  • 打赏
  • 举报
回复
to:superslash
谢谢!
在编译Goods.java时没有报错呀?
改过了还是依旧报错?
superslash 2005-10-17
  • 打赏
  • 举报
回复
public Goods(int goodsId,String code,String name,int kind,String memoryCode,
String barCode,String unit,int qty,int onHand,double price,double rent,
String description,String publisher,int Country,Date publishDate,int closed)
中的int Country变量名小写int country
yellowpage3403 2005-10-17
  • 打赏
  • 举报
回复
没人能帮忙一下么?
yellowpage3403 2005-10-17
  • 打赏
  • 举报
回复
up!
yellowpage3403 2005-10-17
  • 打赏
  • 举报
回复
up!

81,122

社区成员

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

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