Sunday, 18 August 2013

hey,I am trying to execute a batch with prepared statement but getting null pointer exception,plz give some solution

hey,I am trying to execute a batch with prepared statement but getting
null pointer exception,plz give some solution

i am trying to execute a batch with prepared statement but getting null
pointer exception.Here is my code,plz help in finding bug..
public ArrayList<BeanStaff> getLeaveStatus(ArrayList<String> name,String
date) throws Exception {
ArrayList<BeanStaff> lDetail = new ArrayList();
String r = name.toString();
Statement st = null;
DateFormat formatter = null;
Date convertedDate = null;
formatter = new SimpleDateFormat("dd/MM/yyyy");
convertedDate = (Date) formatter.parse(date);
java.sql.Date dt = new java.sql.Date(convertedDate.getTime());
try {
PreparedStatement ps = con.prepareStatement("Select Leave_Status
from staff_leave_detail join employe on staff_leave_detail.Emp_ID
= employe.Emp_ID where Leave_Start_Date=? and Emp_F_Name=?");
ps.setDate(1,dt);
ps.setString(2,r);
ps.addBatch();
if(r.equals(name.size())){
ps.executeBatch();
}
while(ps.getMoreResults()){
rs = ps.getResultSet();
}
while(rs.next())
{
BeanStaff sf = new BeanStaff();
sf.setLeaveStatus(rs.getString("Leave_Status"));
lDetail.add(sf);
}}
catch (Exception e) {
System.out.println(e);}
finally {
con.close();
st.close();
}
return lDetail;}

No comments:

Post a Comment