任何机构都可以解释将struts.1传递给数据库oracle的替代方式
public class Myaction extends Action
{
public ActionForwards excecute(-,-,-,-)
{
//donot write jdbc code here, where we write this jdbccode
}
}
答案 0 :(得分:0)
你会想要使用DAO和DTO设计模式。您可能希望将此article作为读取
答案 1 :(得分:0)
这是一个非常简单的例子,只是为了给你一个想法。您可以创建一个DAO类,并在其中有一个方法,其中包含所有与jdbc相关的内容,例如获取连接和设置会话。 DAO中的该方法查询数据库,并在动作类中处理结果。
你的动作类:
public class Myaction extends Action
{
public ActionForwards excecute(-,-,-,-)
{
//donot write jdbc code here, where we write this jdbccode
MyDAO dao = new MYDAO();
Resultset result = dao.getResults();
}
}
DAO课程
public class MyDAO{
public ResultSet getResults(){
private Session session = MyUtil.getSession();
String query = "SELECT * from MY_TABLE";
PreparedStatement stmt = con.prepareStatement(query);
Connection con = session.connection();
ResultSet result = stmt.executeQuery();
return result;
}
}