java web Dao使用
publicclassProductDaoextendsBaseDao{publicvoidinsert(Productobj)throwsException{Strin...
public class ProductDao extends BaseDao {
public void insert(Product obj)throws Exception{
String sql="insert into product value(?,?,?,?)";
Connection conn=getConnection();
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,obj.getProductid());
pstmt.setString(2,obj.getCategory());
pstmt.setString(3,obj.getName());
pstmt.setString(4,obj.getDescn());
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
}
测试类 :
package dao;
import domain.Product;
public class TestProductDao {
public static void main(String[] args) throws Exception{
ProductDao dao=new ProductDao();
Product obj=null;
obj.setProductid("007");
obj.setCategory("FISH");
obj.setName("什么鱼");
obj.setDescn("好鱼好鱼!");
dao.insert(obj);
}
}
请问怎么运行不了呢?? 难道要在前面Dao类中先对inset()方法调用实现?? 展开
public void insert(Product obj)throws Exception{
String sql="insert into product value(?,?,?,?)";
Connection conn=getConnection();
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,obj.getProductid());
pstmt.setString(2,obj.getCategory());
pstmt.setString(3,obj.getName());
pstmt.setString(4,obj.getDescn());
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
}
测试类 :
package dao;
import domain.Product;
public class TestProductDao {
public static void main(String[] args) throws Exception{
ProductDao dao=new ProductDao();
Product obj=null;
obj.setProductid("007");
obj.setCategory("FISH");
obj.setName("什么鱼");
obj.setDescn("好鱼好鱼!");
dao.insert(obj);
}
}
请问怎么运行不了呢?? 难道要在前面Dao类中先对inset()方法调用实现?? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询