Friday, October 3, 2008

Making a method returning arraylist in java Struts using jdbc

Here is the sample method is given which is retuning the database values with the arraylist.

public ArrayList Dates(String datefrom,String dateto) throws DataAccessException,java.sql.SQLException{

ArrayList list1= new ArrayList();

MYSQLConnect connect=new MYSQLConnect();

Connection conn = connect.connection;

Statement smt = conn.createStatement();

ResultSet rs;

//int no=0;

//String[]str=new String[20];

//write select query for checking password

String query="select DISTINCT `date` from attendance where (Date between

'"+datefrom+"' and '"+dateto+"')";

rs=smt.executeQuery(query);

while(rs.next()== true){

StudentDetailsForm form =new StudentDetailsForm();

form.setDateFrom(rs.getString("date"));

list1.add(form);

}

smt.close();

rs.close();

conn.close();

return list1;

}

No comments: