我的数据库表中有4条记录,但我只从该函数中获取一条记录。请检查我的代码一次。当我在这个函数中调用getMaterialTransferRecords()函数时,我有另一个函数getMaterialUnit()。我无法找到解决方案。请任何人帮助我。
这是我在sqlyog中执行的查询。请检查一次
以上是我的查询,下面是结果。
这就是我调用函数的方式。
// Fetch Data from User Table
int startPageIndex = Integer.parseInt(request.getParameter("jtStartIndex"));
int recordsPerPage = Integer.parseInt(request.getParameter("jtPageSize"));
String jtSorting = request.getParameter("jtSorting");
MaterialTransferUtils utils = new MaterialTransferUtils();
//System.out.println("Cash Purchases Start Page Index:"+startPageIndex+" recordsPerPage:"+recordsPerPage);
if(jtSorting != null)
{
jtSorting = jtSorting.replaceAll("material_destn_code", "material_destn_code");
jtSorting = jtSorting.replaceAll("date", "transferred_on");
}
// Fetch Data from Cash Memo Table
mtList = utils.getMaterialTransferRecords(startPageIndex, recordsPerPage,jtSorting);
请检查一次代码。
public List<MaterialTransferBean> getMaterialTransferRecords(int startPageIndex, int recordsPerPage,String jtSorting)
{
List<MaterialTransferBean> list = new ArrayList<MaterialTransferBean>();
con=com.s2s.bssb.database.ConnectionFactory.getConnection();
MaterialTransferBean mtbean = null;
String sortStr = "material_destn_code DESC";
if(null != jtSorting)
sortStr = jtSorting;
String query = "SELECT sno,material_loc_code,transferred_on,mr_no,do_no,material_destn_code,material_id,quantity,unit_price, "
+ "gst,remarks FROM material_transfer ORDER BY "+sortStr+" LIMIT "+recordsPerPage+" offset "+startPageIndex+"";
System.out.println(query);
if(con!=null){
try{
ps=con.prepareStatement(query);
rs=ps.executeQuery();
while(rs.next()){
MaterialTransferBean bean = new MaterialTransferBean();
bean.setSno(rs.getInt("sno"));
bean.setMaterial_loc_code(rs.getString("material_loc_code"));
bean.setDate(rs.getDate("transferred_on"));
bean.setMr_no(rs.getString("mr_no"));
bean.setDo_no(rs.getString("do_no"));
bean.setMaterial_destn_code(rs.getString("material_destn_code"));
bean.setQuantity(rs.getDouble("quantity"));
bean.setUnit_price(rs.getDouble("unit_price"));
bean.setAmount(rs.getDouble("quantity")*rs.getDouble("unit_price"));
bean.setGst(((rs.getDouble("quantity")*rs.getDouble("unit_price"))*(rs.getDouble("gst")))/100);
bean.setTtl_amount((rs.getDouble("quantity")*rs.getDouble("unit_price"))+(((rs.getDouble("quantity")*rs.getDouble("unit_price"))*(rs.getDouble("gst")))/100));
bean.setRemarks(rs.getString("remarks"));
mtbean = new MaterialTransferBean();
mtbean = getMaterialUnit(rs.getInt("material_id"));
bean.setMaterial(mtbean.getMaterial());
bean.setUnit(mtbean.getUnit());
list.add(bean);
}
rs.close();
com.s2s.bssb.database.ConnectionDB.close(con);
com.s2s.bssb.database.ConnectionDB.close(ps, con);
}catch(SQLException sql_ex){
sql_ex.printStackTrace();
}
}else{
System.out.println("Connection Not Created");
}
return list;
}
public MaterialTransferBean getMaterialUnit(int material_id){
MaterialTransferBean bean = null;
con=com.s2s.bssb.database.ConnectionFactory.getConnection();
String query = "select material,unit from materials where id=?";
if(con!=null){
try{
ps=con.prepareStatement(query);
ps.setInt(1, material_id);
rs=ps.executeQuery();
while(rs.next()){
bean = new MaterialTransferBean();
bean.setMaterial(rs.getString("material"));
bean.setUnit(rs.getString("unit"));
}
}catch(SQLException sql_ex){
sql_ex.printStackTrace();
}
}
return bean;
}