Take a look at a very good db example app that uses Struts on iBatis.com
caled PetStore 3.
.V
Ricky wrote:
> hi, there,
>
> with my project i had several queries about get datasource in struts. i know how
> to get datasource in struts, just as in myAction, use getDataSource method and
> return DataSource object, and go on to get connection ....
>
> i also know the logic beans between the Controller and Module, so i create a
> logic bean ,i don't know how to get datasourc of pass the datasource, in some
> tutorial , i got a way to solve this, create a method getDAO(HttpServletRequest
> request) and pass the request to the method to get DataSource, i was lost here, i
> dont' know what should i return in getDAO, should i return a DataSource object or
> others and in my logic bean i can use the datasource and also get connection ,
> statement and resultset object , there i have to close it after i finish my process
> ....what do you think of this i did ? in general, when i got a DataSource, i will
> got a connection from datasource and a PrepareStatement and also a ResultSet , when
> i finished my process, i can close all object i opened before in final method of try
> ...catch...experession.. now what should i do to return a proper object in getDAO
> method and in logic beans i can use the object to process logic business...
>
> i appologized for this ... i hope you can give me some suggestion or flow......
> thanx!
>
> now here is my flow of struts framework to pass the datasource to the logic beans...
> i hope you can reword if you have some good idea...of correct my mistake... :)
>
> myAction :
>
> myAction extends Action() {
> public ActionForward execute(ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response) {
> LogicBean bean = new LogicBean();
> Object objcet = bean.doMethod(getDAO(request), other param)
> }
>
> public DataSource getDAO(HttpServletRequest request) {
> DataSource ds = null;
> ds = getDataSource(request);
> return ds;
> }
> }
>
> and in my logic bean :
>
> class LogicBean {
> public Objct doMethod(DataSource ds, other param) {
> try {
> Connection conn = ds.getConnection();
> PrepareStatment stmt = conn.prepareStatment("SELECT .......");
> stmt.setInt(1,....);
> ResultSet rs = stmt.executeQuery();
> ....
> return Object.....;
> } catch (SQLException ex) {
> ex.printStactTrace();
> } final {
> try {
> rs.close();
> stmt.close();
> conn.close()
> } catch (Exception ex) {
> ex.printStactTrace();
> }
> }
> return null;
> }
> }
>
> should i pass the DataSource to my logic beans? otherwise what object should i
> pass....
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]