You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "supriya .pelluru" <su...@gmail.com> on 2008/04/28 15:28:21 UTC

how can we insert the caluclated value in action class

Hi to All


           <sqlMap namespace="UserSqlMap">
 <typeAlias alias="booksform" type="ibat.log.IbatisBooksForm"/>

 <parameterMap id="returndate"   class="java.util.Date">

 <parameter property="returndate" jdbcType="DATE"
        javaType="java.lang.String" mode="IN"/>


</parameterMap>
<insert id="insertUserSelectedDateDetails" parameterClass="booksform"
parameterMap="returndate">
<selectKey   resultClass="int"   keyProperty="id">
SELECT IBATISUSERID.NEXTVAL AS id FROM DUAL
</selectKey>
insert into  IBATISUSERBOOK (BOOKID,MEMBERID,SELECTEDDATE,RETURNDATE)
values(#bookid#,#bookname# ,#selecteddate#,?)
</insert>
 </sqlMap>
this is the sqlmap code

this is class file code
public  void userinsertInfo(IbatisBooksForm form) {

  String currentTime =null;
     String notallowed=null;

     String  returnvalue=null;
 String selectdate=form.getSelecteddate();

 String username =form.getSelectedusername();
  Date today = new Date();
  SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
 // Date datenewformat = null;

  Date myDate=null;
  System.out.println("the checking date my date");

  try{

     myDate = sdf.parse(selectdate);
  System.out.println("the checking date my date"+myDate);


  Calendar calendar = Calendar.getInstance();


  calendar.setTime(myDate);

  calendar.add(Calendar.DATE, 14);

  myDate = calendar.getTime();

  System.out.println("after add the days"+myDate);

  }

  catch(Exception e)
  {
   System.out.println("the exception value"+e.getMessage());
  }
  if (myDate != null)
  {


   String date = "dd/MMMM/yyyy";
   SimpleDateFormat sdf2 = new SimpleDateFormat(date);
    currentTime = sdf2.format(myDate);


 System.out.println("         Date Ordered:            "+currentTime);


 System.out.println("the date"+currentTime);

  System.out.println("the use selection name in bao"+username);





  Connection con = null;


  try{
   int sno = form.getUserprimaryKey();

   HashMap map = new HashMap();

      map.put("bookid",new Integer(form.getUserprimaryKey()));

    map.put("returndate", new Integer(currentTime));

   int userbookid =  form.getUserprimaryKey();
    String bookselectusername=  form.getSelectedusername();
     String userselecteddate= form.getSelecteddate();

    form.setBookid(userbookid);
    form.setSelectedusername(bookselectusername);
    form.setSelecteddate(userselecteddate);
   // form.setCurrentTime(currentTime);

   sqlMap.insert("insertUserSelectedDateDetails", form);
  }catch(Exception e3)
  {
   System.out.println("the user insert selected date"+e3.getMessage());
  }
  }
 }

here there is no field  currentTime in action form  . i am calculate that
currentTime here . and i have to insert that one in ibatisuserbook table
for that i am user "returndate" parameterMap for storing the result i am
sending that by using hashmap plz see that in classfile .now my pronlem is
i am not getting any sqlquery exception . and also any value is not
inserting in i
ibatisuserbook table .

if any one know solution for this problem plz send me reply .