1, first define action Formbean:
package com.bhsky.webis.system;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class UsersActionForm extends ActionForm {
private String usr_id;
private String usr_name;
public void setUsr_id(String usr_id) {
this.usr_id = usr_id;
}
public String getUsr_id() {
return usr_id;
}
public String getUsr_memo() {
return usr_memo;
}
public void setUsr_name(String usr_name) {
this.usr_name = usr_name;
}
}
2. Write the common method of assigning values to Actionformbean:
//function: Completes the transformation of the ResultSet object to the object of the ArrayList object for the collection
//para:sql, the specified query SQL
//para:classname, SQL corresponds to the Javabean/formbean class name
//return: a result set with a class classname as a record,
// Completes the transformation of the ResultSet object to the ArrayList object as a collection of ClassName objects
Public ArrayList Select (String sql,string className) {
Arrayl ist paralist=new ArrayList ();
try{
if (conn = = null) {
Connection ()
PreparedStatement stmt = conn.preparestatement (sql);
ResultSet rs = Stmt.executequery ();
String recordvalue= "";
Object C1=null;
Paralist=new ArrayList ();
ResultSetMetaData rsmd = Rs.getmetadata ();
int columnCount = Rsmd.getcolumncount ();
while (Rs.next ()) {
C1=class.forname (className). newinstance ();
for (int i=1; i<=columncount; i++) {
if (rs.getstring (Rsmd.getcolumnname (i))!=null) {
recordvalue= Rs.getstring (Rsmd.getcolumnname (i));
}else{
recordvalue= "";
Method
M=c1.getclass (). GetMethod (Getsetmethodname (Rsmd.getcolumnname (i)),
New class[]{ Recordvalue.getclass ()});
M.invoke (c1, new Object[]{recordvalue});
}
Paralist.add (c1);
}catch (SQLException ex) {
}catch (classnotfoundexception e) {
}catch (nosuchmethodexception e) {
}ca TCH (InvocationTargetException e) {
}catch (illegalaccessexception e) {
}catch (instantiationexception e) {
} finaly{
CloseConnection ();
return paralist;
}
}