Help me to control the transactions from jsp to java bean

Please anyone can guide me how to control the transactions from jsp to java bean. I am using the Websphere studio 5.1 to develop the database application. I would like to know two method to handle the database. First, I would like to know how I can control the transactions from jsp by using java bean which is auto generated for SQL statement to connect to the database. Following code are jsp and java bean.....
// call java bean from jsp
for (i=0;i<10;i++)
addCourse.execute(yr,sem,stdid,course,sec);
I write this loop in jsp to call java bean..
here is java bean for AddCourse.java
package com.abac.preregist.courseoperation;
import java.sql.*;
import com.ibm.db.beans.*;
* This class sets the DBModify property values. It also provides
* methods that execute your SQL statement and return
* a DBModify reference.
* Generated: Sep 7, 2005 3:10:24 PM
public class AddCourse {
     private DBModify modify;
     * Constructor for a DBModify class.
     public AddCourse() {
          super();
          initializer();
     * Creates a DBModify instance and initializes its properties.
     protected void initializer() {
          modify = new DBModify();
          try {
               modify.setDataSourceName("jdbc/ABAC/PreRegist/PRERMIS");
               modify.setCommand(
                    "INSERT INTO informix.javacourseouttemp " +
                    "( yr, sem, studentid, courseid, section ) " +
                    "VALUES ( :yr, :sem, :studentid, :courseid, :section )");
               DBParameterMetaData parmMetaData = modify.getParameterMetaData();
               parmMetaData.setParameter(
                    1,
                    "yr",
                    java.sql.DatabaseMetaData.procedureColumnIn,
                    java.sql.Types.SMALLINT,
                    Short.class);
               parmMetaData.setParameter(
                    2,
                    "sem",
                    java.sql.DatabaseMetaData.procedureColumnIn,
                    java.sql.Types.SMALLINT,
                    Short.class);
               parmMetaData.setParameter(
                    3,
                    "studentid",
                    java.sql.DatabaseMetaData.procedureColumnIn,
                    java.sql.Types.CHAR,
                    String.class);
               parmMetaData.setParameter(
                    4,
                    "courseid",
                    java.sql.DatabaseMetaData.procedureColumnIn,
                    java.sql.Types.CHAR,
                    String.class);
               parmMetaData.setParameter(
                    5,
                    "section",
                    java.sql.DatabaseMetaData.procedureColumnIn,
                    java.sql.Types.SMALLINT,
                    Short.class);
          } catch (SQLException ex) {
               ex.printStackTrace();
     * Executes the SQL statement.
     public void execute(
          String userid,
          String password,
          Short yr,
          Short sem,
          String studentid,
          String courseid,
          Short section)
          throws SQLException {
          try {
               modify.setUsername(userid);
               modify.setPassword(password);
               modify.setParameter("yr", yr);
               modify.setParameter("sem", sem);
               modify.setParameter("studentid", studentid);
               modify.setParameter("courseid", courseid);
               modify.setParameter("section", section);
               modify.execute();
          // Free resources of modify object.
          finally {
               modify.close();
     public void execute(
               Short yr,
               Short sem,
               String studentid,
               String courseid,
               Short section)
               throws SQLException {
               try {
                    //modify.setUsername(userid);
                    //modify.setPassword(password);
                    modify.setParameter("yr", yr);
                    modify.setParameter("sem", sem);
                    modify.setParameter("studentid", studentid);
                    modify.setParameter("courseid", courseid);
                    modify.setParameter("section", section);
                    modify.execute();
               // Free resources of modify object.
               finally {
                    modify.close();
     * Returns a DBModify reference.
     public DBModify getDBModify() {
          return modify;
I would like to know that how can I do for autocommit from jsp. For example, the looping is 10 times which mean I will add 10 records to the db. If the last record is failed to add to db, "how can I rollback the perivious records?" or guide me to set the commit function to handle that case. Thanks a lot for take your time to read my question.

Hello.
The best method is using a session bean and container managed transactions. Other method is using sessions bean and the user transaction object (JTA-JTS).
so, JDBC has transaction management too.
good luck.

Similar Messages

  • Questions/answers from jsp to java bean

    Hi
    This is what i need to do .
    I am showing some questions, say 4 of them , and radio buttons(yes/no) as answers in the JSP.
    Now how do i transfer these questions and their answers from jsp to java bean .
    I did try hashmap ,but not quite working .
    any help?
    thanks

    Name each radiobutton differently, and then provide 1 property and accessor methods for each of your four answers in the JavaBean, with the same name as specified in the HTML FORM.
    So in the HTML:
    <input type="radio" name="answerOne" value="true"...>
    and then have a property named answerOne with accessor methods in the javaBean...

  • How to pass value from jsp to java bean

    I have huge problem . How to pass value from jsp value to java bean.Please replay me soon

    Use the <jsp:setProperty> tag. There are several ways to use it. The one you probably want is:
    <jsp:setProperty name="bean_name"  property="property_name"  value="the_value_you_want_to_set"/>

  • Is it possible to call the SQL Server DB from jsp to java?

    im doing a configurable system where you can create your own table using the system. i can do the creation of table by running the statement CREATE TABLE...........(with attributes) in java.
    Let's say i have created tblST1 with attributes st_ID, st_Name, st_Description.
    My problem is i dont know if it's possible to retrieve all the attributes from jsp to java.

    jverd: i need your help. Iv read all the links u posted but im having a hard time in understanding them.
    For the site http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSetMetaData.html , there's a code there which is...
    ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
    ResultSetMetaData rsmd = rs.getMetaData();
    int numberOfColumns = rsmd.getColumnCount();
    boolean b = rsmd.isSearchable(1);
    what i did was, i inserted it in my java code which is :
    public boolean checkFieldTable2()
              boolean checked = false;
              try
                   IRMS_DBConnect db = new IRMS_DBConnect();
                   db.openCon();
                   ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
              ResultSetMetaData rsmd = rs.getMetaData();
              int numberOfColumns = rsmd.getColumnCount();
              boolean b = rsmd.isSearchable(1);
                   db.closeCon();
                   checked = true;
              catch (Exception ex)
                   System.out.println("Error on Execution: " + ex);
              return checked;
    and i compiled it and there was an error that the variable stmt was not initialized. Am i doing the right way?
    Can anyone help me pls? pls pls pls

  • Transaction from Jsp

    Is it posible to use JTA Transaction from JSP?
              or do I need to user JDBC?
              What is the recomended practice?
              Chriss Corcino
              

    You will probably need to get a 3rd party JDBC driver to connect to your IMS database. Another other option would be to write a library that does the necessary JNI calls and then call that library.
    Hope this helps -- Jeff

  • TS1930 Hi All, I'm using iTunes 10.6.3.25 and i don't see the option of "Enable disk use" here so can someone kindly help me in copying the videos from my iPod Touch to my PC, Thank you.

    Hi All, I'm using iTunes 10.6.3.25 and i don't see the option of "Enable disk use" here so can someone kindly help me in copying the videos from my iPod Touch to my PC, Thank you.

    There is no enable disk use option for iOS Devices.  See this article for instructions on copying videos and photos from your iOS device to your PC.
    iOS: Importing personal photos and videos from iOS devices to your computer
    B-rock

  • Please help me to change the language from Danish to swedish i PS CS5

    please help me to change the language from Danish to swedish i PS CS5
    In the program (interfaces) i can only choose Danish

    There is nothing to choose. The language is determined by your serial number and the choice of language during installation. You need to reinstall in that language.
    Mylenium

  • I can't control the volume from my iphone 4 headset. What can I do???

    I can't control the volume from my iphone 4 headset. What can I do???

    Go to Settings > Sounds. There is this option call Change With Buttons. Is it On or Off?

  • The MSDTC transaction manager failing : It was unable to pull the transaction from the source transaction manager due to communication problems

    Microsoft Tech Gurus,
    Can you please assist on this issue. ? There are 3 different errors stacks for this issue - Our Application is not connecting with MS SQL Server. Everything was fine until Monday. There are changes have done on those Apps and DB servers.
    Please refer the attached document - which has all the errors with details. Appreciate all your support.!
    Error 1 :
    TISAppenderLog4net.Log4NetException: The underlying provider failed on Open. ---> System.Data.EntityException: The underlying provider failed on Open. ---> System.Transactions.TransactionManagerCommunicationException:
    Communication with the underlying transaction manager has failed. ---> System.Runtime.InteropServices.COMException: The MSDTC transaction manager was unable to pull the transaction from the source transaction manager due to communication problems. Possible
    causes are: a firewall is present and it doesn't have an exception for the MSDTC process, the two machines cannot find each other by their NetBIOS names, or the support for network transactions is not enabled for one of the two transaction managers. (Exception
    from HRESULT: 0x8004D02B)
    Error 2 :
    TISAppenderLog4net.Log4NetException: Installation of the application [TestApp] failed ---&gt; TiS.Core.TisCommon.TisException: Installation of the application [TestApp] failed
    Error 3 :
    TISAppenderLog4net.Log4NetException: Cannot open database "TestApp_Workflow" requested by the login. The login failed.
    Login failed for user 'eflow_user'. ---> System.Data.SqlClient.SqlException: Cannot open database "TestApp_Workflow" requested by the login. The login failed.
    Login failed for user 'eflow_user' at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1
    wrapCloseInAction)

    Error 1:-
    http://blogashwani.blogspot.in/2013/05/dtc-issue-can-not-find-each-other-by.html
    It seemed like a case when (sometimes) machines were  not able to locate each other.
    The solution was simple (as suggested on forums available on the internet)- make identification easier :).
    Either access the machines using IP instead of their names or make a mapping entry in the "hosts" file located at "C:\windows\system32\drivers\etc".
    We took the "hosts" file approach and there were no errors once we made the changes.
    Error 3 :
    Try login from mssql using that account check it verifed
    Distributed Transaction Coordinator restart and check.

  • Pass a value to the procedure from jsp

    Hi I need a help..
    I have a jsp page which has the value , And I have one stored procedure in a java file. I have to pass this
    selected month to that stored procedure. there are 2 input parameters and one out parameter which returns a date files. If i hard code the input parameters i am able to get the date field. the first parameter is in session, that is divisionCode. So no problem with that... but other value the selectedMoth "12/2003" should be passed from the jsp.
    help me how to achive this....
    my jsp code is
    <%
    String selectedMonth = request.getParameter("selectedMonth");
    String monthLastDate = callPLSQLFunc.getmonthLastDate(divisionCode);
    System.out.println("Month Last date is " +monthLastDate);
    %>my calling procedure
    public String monthLastDate(String divisionCode, String selectedMonth) {
            CallableStatement stmt = null;
            ResultSet rs=null;
            String lastDate ="";
          try {
              System.out.println("calling the procedure for month end date");
           //  stmt = con.prepareCall ("{?= call easmsa_front_end_routines_pkg.get_month_end_date(?,?)}");
             System.out.println("calling the procedure for month end date");
            stmt = con.prepareCall("begin easmsa_front_end_routines_pkg.get_month_end_date_prc(?,?,?); end;");
            stmt.setString(1,divisionCode);
            System.out.println("division Code is " +divisionCode);
            System.out.println("The last_date 1 ");
           //  stmt.registerOutParameter(2, oracle.jdbc.OracleTypes.VARCHAR);
             stmt.setString(2,selectedMonth);
             System.out.println("The last_date 2 " +selectedMonth);
             stmt.registerOutParameter(3, oracle.jdbc.OracleTypes.DATE);
             System.out.println("The last_date 3 ");
             stmt.execute();
             System.out.println("getting the value");
         //    lastDate = stmt.getDate(3);
             System.out.println(stmt.getDate(3));
        //     System.out.println("The last_date " +lastDate);
            } catch (SQLException e) {
                e.printStackTrace();
            return lastDate;
        public String getmonthLastDate(String divisionCode,String selectedMonth){
            String monthLastDate = monthLastDate(divisionCode,selectedMonth);
            return monthLastDate;

    Well, you'd just pass the parameter ....
    String monthLastDate = callPLSQLFun.getmonthLstDate(divisionCode, selectedMonth);
    [/code[
    ... or am I totall misunderstanding your question??
    Also, you have two methods which are public, and all one does is call the other with exactly the same parameters passed.  Why not just call monthLastDate() instead of getmonthLastDate() ... it does exactly th same thing, only without the extra call.
    I think maybe you need to grasp the basics of Java a little better before delving into the world of JSP.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Error while accessing a file located in the server from JSP

              Hi
              I am having problem while accessing the file located in the server from a JSP
              page. I am not getting the RealPath from a JSP page using getRealPath(request.getServletpath()).
              The same code is working if the jsp placd under defaultwebApp directory and not
              working if i create a war and deploy the same.
              I am using weblogic server 7.0 trail version.I am setting the context path also.
              Can any help me in this regard.
              Thank And Regards
              Anand Mohan
              

              Hi
              Thank you.Is there a way to read a file which is existing in the war file.
              Regards
              Anand Mohan
              "Wenjin Zhang" <[email protected]> wrote:
              >
              >In Weblogic, if your files are archived in a WAR, you cannot get an entry
              >as individual
              >file since it is only bytes in a large archive file. So getRealPath will
              >give
              >you null result. If you only want the path, try to use other getXXXPath,
              >getURL,
              >or getURI method. If you want to read the content, use getResource.
              >
              >
              >"Anand" <[email protected]> wrote:
              >>
              >>Hi
              >>I am having problem while accessing the file located in the server from
              >>a JSP
              >>page. I am not getting the RealPath from a JSP page using getRealPath(request.getServletpath()).
              >>
              >>The same code is working if the jsp placd under defaultwebApp directory
              >>and not
              >>working if i create a war and deploy the same.
              >>
              >>I am using weblogic server 7.0 trail version.I am setting the context
              >>path also.
              >>
              >>Can any help me in this regard.
              >>
              >>Thank And Regards
              >>
              >>Anand Mohan
              >
              

  • Coming back to the Transaction from a User Exit

    Hi,
    I perform some checks in a User-Exit before saving a transaction & throw an error message if something is not proper. But, the transaction terminates after that. I need to give the user an option to make changes in the transaction. eg, if user exit checks if a certain field should not be empty, the user should have an option to enter the field after the user exit throws the message. How can i go back to the same screen from the exit to achieve the same.
    Thanks in advance.
    Bikash
    This was for a general scenario wherein after an error message triggered by an Exit is displayed, the transaction just terminates.
    Message was edited by: Bikash  Agarwal

    Hi,
    If you give error message, it will leave the current transaction.
    Instead try using some POPUP function module, which will have options 'OK' and 'CANCEL'.
    If user presses 'OK', then allow user to do modifications and if he presses 'CANCEL', then write LEAVE PROGRAM to come out of transaction.
    Hope it helps.
    Regards,
    Shashank

  • Reading the changes with in the Transaction from Toplink

    Typically when we work on a transaction in a SQL Session ( say from SQL*Plus), the DML changes made with in that transaction are visible to the subsequent statements in the same transaction.
    How can we acheive the above functionality with a UnitOfWork? Using a query.ConformResultsInUnitOfWork helps, but only when the Toplink Cache is enabled. Can we achieve the same functionality in Toplink when the Toplink Cache is disabled.
    Many Thanks in advance for any information on this.

    Thanks for the update.
    Below is the sample code. It works fine when the Toplink Cache is enabled on the object. But when it is disabled the executeQuery below fires a query to the database and a null object is returned. I disable the cache at the descriptor level using the statements
    descriptor.alwaysRefreshCache();
    descriptor.disableCacheHits();
    myServerSession =(ServerSession) SessionManager.getManager().getSession("test100");
    myServerSession.login();
    myServerSession.initializeIdentityMaps();
    ClientSession clientSession = myServerSession.acquireClientSession();
    UnitOfWork unitOfWork = clientSession.acquireUnitOfWork();
    // transaction started
    unitOfWork.beginEarlyTransaction();
    Case t = new Case();
    t.setId("Case1");
    t.setClaimNumber("ClaimNo1");
    // object registered with uow, but not yet committed and not in the database
    unitOfWork.registerObject(t);
    Case t1 = new Case();
    t1.setId("Case1");
    //t1 = (Case)unitOfWork.readObject(t1);
    //get the same object using the conformResultsinUnitOfwork
    ReadObjectQuery roq = new ReadObjectQuery(t1.getClass());
    roq.conformResultsInUnitOfWork();
    roq.setSelectionCriteria(roq.getExpressionBuilder().get("id").equal("Case1"));
    t1 = (Case)unitOfWork.executeQuery(roq); //returns null
    //Update some attributes..
    t1.setClaimNumber("ClaimNo2");
    //Commit all changes
    unitOfWork.commit();
    The above sequence of statements works from a SQL prompt, but not from Toplink.

  • Please help me! display the record from the database.

    Hi, all, please help me with the following question. I run my code on the web, the record display on the screen, but when I run again, even I did not put any data into the "memo form", the system display the previous record again which I do not need to post again. Could you please tell me how to correct the code?
    <%@ page language="java" contentType="text/html; charset=Shift_JIS" %>
    <%@ page import="beanYama.*,java.sql.*,java.util.*,java.text.*" %>
    <HTML>
    <HEAD>
    <TITLE>Form Example</TITLE>
    </HEAD>
    <BODY BGCOLOR="#ffffcc">
         <%!      String userid="";
              String memo_create_day="";
              String memo="";     
         %>
         <% if (request.getParameter("userid")==null && request.getParameter("memo_create_day") == null
              && request.getParameter("memo") == null) { %>    
         <LEFT>
         <H2>���`�� �� ����</H2>
         <FORM METHOD="GET" ACTION="memocorrect.jsp">
         <P>
              ���`��1��: <input type="text" name="userid" size=26>
         <P>
              ����: <input type="text" name="memo_create_day" size=26>
         <P>     
              ����: <input type="text" name="memo" size=100>
         <P>
              <input type="submit" value="Submit">
         </FORM>
         </LEFT>
         <% } else { %>  
    <%
    userid = request.getParameter("userid");
    memo_create_day= request.getParameter("memo_create_day");
    memo= request.getParameter("memo");
    %>
    <% } %>
    <%
         boolean proceed = false;
              if(userid != null && memo_create_day != null && memo != null)
                        proceed = true;
         Class.forName("org.gjt.mm.mysql.Driver");
         Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/progress?user=ntjs&password=ntjs&useUnicode=true&characterEncoding=Shift_JIS");
         String sql = "insert into zhangmemo (userid,memo_create_day,memo) values (?, ?, ?)";
         PreparedStatement stmt = conn.prepareStatement(sql);
         if (proceed) {
         stmt.setString(1, userid);
         stmt.setString(2, memo_create_day);
         stmt.setString(3, memo);
         stmt.executeUpdate();
         if (userid==null && memo_create_day==null && memo==null) {
         out.println("<b>Please enter your memo</b>" + "</b>&nbsp"+"<b> </b>");
         stmt.close();
         conn.close();
         else {
         Statement stmt1=conn.createStatement();
         ResultSet rsq=stmt1.executeQuery("SELECT userid AS userid1, memo_create_day AS memo_create_day1, memo AS memo1 FROM zhangmemo");
         while(rsq.next()){
         out.println("<b>���`��:" + rsq.getString("userid1")+ "</b>&nbsp"+"<b> </b>");
         out.println("<b>����:" + rsq.getString("memo_create_day1")+ "</b>&nbsp"+"<b> </b>");
         out.println("<b>����:" + rsq.getString("memo1")+ "</b>&nbsp"+"<b> </b>");
         stmt.close();
         stmt1.close();
         conn.close();
    %>
    </BODY>
    </HTML>
    Thanks a lot!
    Nina

    1. Please learn JSP Coding standards. Your code is a mess.
    2. It may be because you are setting your String variables to "" empty string which is not the same as null. Try doing the following...
    <HTML>
    <HEAD>
    <TITLE>Form Example</TITLE>
    </HEAD>
    <BODY BGCOLOR="#ffffcc">
    <%
      String userid = request.getParameter("userid");
      String memo_create_day = request.getParameter("memo_create_day");
      String memo = request.getParameter("memo");
    %>
    <% if userid == null && memo_create_day == null
    && memo == null) { %>
    <LEFT>
    <H2>���`�� �� ����</H2>
    <FORM METHOD="GET" ACTION="memocorrect.jsp">
    <P>
    ���`��1��: <input type="text" name="userid" size=26>
    <P>
    ����: <input type="text" name="memo_create_day" size=26>
    <P>
    ����: <input type="text" name="memo" size=100>
    <P>
    <input type="submit" value="Submit">
    </FORM>
    </LEFT>
    <%
    boolean proceed = false;
    if(userid != null && memo_create_day != null && memo != null)
    proceed = true;
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/progress?user=ntjs&password=ntjs&useUnicode=true&characterEncoding=Shift_JIS");
    String sql = "insert into zhangmemo (userid,memo_create_day,memo) values (?, ?, ?)";
    PreparedStatement stmt = conn.prepareStatement(sql);
    if (proceed) {
    stmt.setString(1, userid);
    stmt.setString(2, memo_create_day);
    stmt.setString(3, memo);
    stmt.executeUpdate();
    if (userid==null && memo_create_day==null && memo==null) {
    out.println("<b>Please enter your memo</b>" + "</b> "+"<b> </b>");
    stmt.close();
    conn.close();
    else {
    Statement stmt1=conn.createStatement();
    ResultSet rsq=stmt1.executeQuery("SELECT userid AS userid1, memo_create_day AS memo_create_day1, memo AS memo1 FROM zhangmemo");
    while(rsq.next()){
    out.println("<b>���`��:" + rsq.getString("userid1")+ "</b> "+"<b> </b>");
    out.println("<b>����:" + rsq.getString("memo_create_day1")+ "</b> "+"<b> </b>");
    out.println("<b>����:" + rsq.getString("memo1")+ "</b> "+"<b> </b>");
    stmt.close();
    stmt1.close();
    conn.close();
    %>
    </BODY>
    </HTML>

  • How to send the data from jsp page to excel ???

    hi all,
    i want to send the data from my jsp form to excel sheet. any one can help me ??

    Hope this sample code might help :
    StringBuffer data = new StringBuffer();
    OutputStream ostream = response.getOutputStream();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader( "Content-Disposition",
    "attachment; filename=sample.xls" );
    ostream.write(data.toString().getBytes());
    ostream.flush();
    Try it out.
    Swathi

Maybe you are looking for

  • Pay Scale inrease - Custom Program

    HI  Guyz,    A custom program is developed for the pay scale increase  and it should be  run on a regular basis as a background job to update the pay increase of the employees who have completed either 60 days or 6 months or 9 months from the hire or

  • HT1766 HOW CAN I CHANGE MY BACKUP FOLDER FROM THE C DRIVE TO ANOTHER?????

    HOW CAN I CHANGE MY BACKUP FOLDER FROM THE C DRIVE TO ANOTHER????? because my c drive in the windows computer gets filled and i need to back up my ipod to a portable hard disk.. bt i dont know how to do it.. plz help

  • MacBook Pro Harddrive help!!!

    Before putting my itunes library (from my old computer) on my MacBook, My memory was at 230gb. My whole library is only 60gb, and now my MBP's harddrive space is starting to drop below 20gb!? Why is this? PLEASE HELP THANKS IN ADVANCE

  • How to maintain the fields mandatory in Opportunity and quotation SAP CRM?

    Hello All, I have the following two requirements : 1.Need to mark the fields as mandatory in SAP CRM Opportunity (description,sales prospect,phase,status,opportunity group,origin ,product(description,quantity,expected total value) ,Milestones(Start d

  • HD replaced in 24" Intel iMac

    My iMac is out of warranty, and the 500Gb drive died recently. I was able to find instructions online to replace the drive (much easier that I expected). I replaced it with a Western Digital 1Tb drive. It's working fine now, but the drive is noticeab