//--------------------------
DIE REPOSITORY
//--------------------------
package student;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.sql.PreparedStatement;
import java.sql.Connection;
public class Chemikalien_repositoryBean {
private List l_chemikalien = new ArrayList();
private List l_chemikalientx = new ArrayList();
private int chn = 1;
private Connection con = null;
private int id = 0;
private static Chemikalien_repositoryBean chemr = new Chemikalien_repositoryBean();
public static Chemikalien_repositoryBean getInstance() {
return chemr;
}
public Chemikalien_repositoryBean() {
try {
con = ConnectionController.getConnection();
} catch (Exception ex) {
System.err.println(ex);
System.out.println("Verbindung konnte nicht aufgebaut werden" +
" - Chemikalien_repositoryBean");
}
}
public void setChn(int chn){
this.chn = chn;
System.out.println(chn+"ich bin set chn");
readDataBasetx();
getL_chemikalientx();
}
public List getL_chemikalientx() {
System.out.println(chn+"ich bin die repo");
readDataBasetx();
return l_chemikalientx;
}
private void readDataBasetx() {
l_chemikalientx.clear();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = con.prepareStatement(
"SELECT "+
"ch_id, ch_name, "+
"ch_name_sort, "+
"ch_name_zusa, "+
"ch_sum_form, "+
"ch_ent_kurzb, "+
"ch_gef_bez, "+
"ch_notiz, "+
"ch_zuo_kbez, "+
"ch_sta_kurzb, "+
"ch_rsa_bez, "+
"ch_ssa_bez "+
"FROM Chemikalien where ch_id = "+chn+" "+
"ORDER BY ch_id");
rs = pstmt.executeQuery();
while (rs.next()) {
ChemikalienBean myChemikalie = new ChemikalienBean(
rs.getInt("ch_id"),
rs.getString("ch_name"),
rs.getString("ch_name_sort"),
rs.getString("ch_name_zusa"),
rs.getString("ch_sum_form"),
rs.getString("ch_ent_kurzb"),
rs.getString("ch_gef_bez"),
rs.getString("ch_notiz"),
rs.getString("ch_zuo_kbez"),
rs.getString("ch_sta_kurzb"),
rs.getString("ch_rsa_bez"),
rs.getString("ch_ssa_bez")
);
l_chemikalientx.add(myChemikalie);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
} catch (Exception e) {
System.err.println(e);
System.out.println("Fehler in readDataBasetx - Chemikalien_repositoryBean");
} finally {
if (rs != null) {
try {rs.close();
} catch (Exception i) {}
}
if (pstmt != null) {
try {pstmt.close();
} catch (Exception i) {}
}
}
}
//----------------------
DIE ACTION
//----------------------
package student;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
public class Chemikalien_anz_befAction
extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse) {
Chemikalien_ActionForm chemikalien_ActionForm = (Chemikalien_ActionForm)
actionForm;
Chemikalien_repositoryBean cr = Chemikalien_repositoryBean.getInstance();
//Chemikalien_repositoryBean cr = new Chemikalien_repositoryBean();
String chn = servletRequest.getParameter("scrole");
int chi = Integer.parseInt(chn);
System.out.println(chi);
System.out.println("test");
cr.setChn(chi);
//cr.getL_chemikalientx();
return actionMapping.findForward("chemikalien_anz2");
}
}
//--------------------------------
DIE ACTIONFORM
//--------------------------------
/* getter- und setter-Methoden