请大侠们帮忙看看我的问题:构造函数问题,谢了!
编译时报错如下:
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);
}
}
}