用struts2的框架编的一个程序,在连接数据库时出错,说是有
空指针,但是怎么都找不到错在哪里??求教!!!
eclipse的错误报告:
Servlet.service() for servlet default threw exceptionjava.lang.NullPointerException at sale.persistence.GoodsDAOImpl.addGoods(GoodsDAOImpl.java:37)
at sale.service.GoodsFacadeImpl.addGoods(GoodsFacadeImpl.java:18)
at sale.action.GoodsAction.addGoods(GoodsAction.java:143)
----------------------------------
GoodsDAOImpl.java
package sale.persistence;
import
java.sql.SQLException;
import java.util.Date;
import java.sql.*;
import sale.domain.Goods;
import sale.util.DBConnection;
import sale.util.Time;
public class GoodsDAOImpl implements GoodsDAO {
Connection conn=null;
Time now=new Time();
Statement st=null;
PreparedStatement psmt1=null;
ResultSet rs=null;
String time=now.getTime();
public void addGoods(String goodsNam,int warehouseId,String description,double number,double cost)
throws
SQLException {
String sql="insert into Goods " +"(goodsNam,warehouseId,Description,Number,cost)"
+"values('"+goodsNam+"','"+warehouseId+"','"+description+"','"+number+"','"+cost+"','"+time+"')";
try{
try {
conn=DBConnection.getDBC();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn.setAutoCommit(false);
st=conn.createStatement();
st.executeUpdate(sql);
conn.commit();
}catch(SQLException e){
e.printStackTrace();
conn.rollback();
}
conn.setAutoCommit(true);
st.close();
conn.close();
}
public void changeGoods(int goodsId) throws SQLException {
// TODO Auto-generated method stub
}
public void deleteGoods(int goodsId) throws SQLException {
// TODO Auto-generated method stub
}
public void searchGoods(int goodId) throws SQLException {
// TODO Auto-generated method stub
}
}
----------------------------------
GoodsFacadeImpl.java
package sale.service;
import java.sql.SQLException;
import sale.domain.Goods;
import sale.persistence.GoodsDAO;
import sale.persistence.GoodsDAOImpl;
public class GoodsFacadeImpl implements GoodsFacade {
private GoodsDAO goodsDAO;
public GoodsFacadeImpl(){
goodsDAO=new GoodsDAOImpl();
}
public void addGoods(String goodsNam, int warehouseId, String description,
double number, double cost) throws SQLException {
goodsDAO.addGoods(goodsNam, warehouseId, description, number, cost);
}
public void changeGoods(int goodsId) throws SQLException {
// TODO Auto-generated method stub
}
public void deleteGoods(int goodsId) throws SQLException {
// TODO Auto-generated method stub
}
public void searchGoods(int goodId) throws SQLException {
// TODO Auto-generated method stub
}
}
------------------------------------
GoodsAction.java
package sale.action;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.http.HttpServletReque