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

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);
}

}
}
...全文
188 8 打赏 收藏 转发到动态 举报
写回复
用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!
你想当“李逍遥”式的“大侠”吗? 这里无需计算机基础,无需编程经验,你也不必是计算机专业的在校大学生....只要爱好游戏,怀揣梦想! 有一定自主学习能力,跟着刘老师从“编程小白”修炼为游戏研发“大虾”吧!!!学习好Unity,其先决条件是一定要有稳固、扎实的编程基础!课程 《C# For Unity系列之入门篇》配套学习资料链接:http://pan.baidu.com/s/1gflxreN 密码:sou5;刘老师讲Unity学员群(2) 497429806一、热更新系列(技术含量:中高级):A:《lua热更新技术中级篇》https://edu.csdn.net/course/detail/27087B:《热更新框架设计之Xlua基础视频课程》https://edu.csdn.net/course/detail/27110C:《热更新框架设计之热更流程与热补丁技术》https://edu.csdn.net/course/detail/27118D:《热更新框架设计之客户端热更框架(上)》https://edu.csdn.net/course/detail/27132E:《热更新框架设计之客户端热更框架(中)》https://edu.csdn.net/course/detail/27135F:《热更新框架设计之客户端热更框架(下)》https://edu.csdn.net/course/detail/27136二:框架设计系列(技术含量:中级): A:《游戏UI界面框架设计系列视频课程》https://edu.csdn.net/course/detail/27142B:《Unity客户端框架设计PureMVC篇视频课程(上)》https://edu.csdn.net/course/detail/27172C:《Unity客户端框架设计PureMVC篇视频课程(下)》https://edu.csdn.net/course/detail/27173D:《AssetBundle框架设计_框架篇视频课程》https://edu.csdn.net/course/detail/27169三、Unity脚本从入门到精通(技术含量:初级)A:《C# For Unity系列之入门篇》https://edu.csdn.net/course/detail/4560B:《C# For Unity系列之基础篇》https://edu.csdn.net/course/detail/4595C: 《C# For Unity系列之中级篇》https://edu.csdn.net/course/detail/24422D:《C# For Unity系列之进阶篇》https://edu.csdn.net/course/detail/24465四、虚拟现实(VR)与增强现实(AR):(技术含量:初级)A:《虚拟现实之汽车仿真模拟系统 》https://edu.csdn.net/course/detail/26618五、Unity基础课程系列(技术含量:初级) A:《台球游戏与FlappyBirds—Unity快速入门系列视频课程(第1部)》 https://edu.csdn.net/course/detail/24643B:《太空射击与移动端发布技术-Unity快速入门系列视频课程(第2部)》https://edu.csdn.net/course/detail/24645 C:《Unity ECS(二) 小试牛刀》https://edu.csdn.net/course/detail/27096六、Unity ARPG课程(技术含量:初中级):A:《MMOARPG地下守护神_单机版实战视频课程(上部)》https://edu.csdn.net/course/detail/24965B:《MMOARPG地下守护神_单机版实战视频课程(中部)》https://edu.csdn.net/course/detail/24968C:《MMOARPG地下守护神_单机版实战视频课程(下部)》https://edu.csdn.net/course/detail/24979

81,092

社区成员

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

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