Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Why I need to clicked the update button twice to save my data to database?

  1. #1
    Junior Member
    Join Date
    Dec 2023
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why I need to clicked the update button twice to save my data to database?

    I am trying to update my data(MACKEY) to the database, but it didn't update successfully until I press the update bottom twice. The the origin key column in database is null.
    try {
     
    					String mid ="";
    					String tid ="";
     
    					if ("SPB".equals(aaa.get("adapterid_1"))) {
    						System.out.println("modify SPBUPOP Start !");
     
    						if (isSPBUPOPexist) {
    							System.out.println("Got SPBUPOP data!");
    							try {
    								if ("1".equals(request.getParameter("SPBUPOP_Enable"))) {
    									System.out.println("update SPBUPOP status = A !");
    									spbupopstmt = spbupop_conn.prepareStatement(
    											"UPDATE B2BMERCONFIG SET STATUS = 'A',MACKEY = ? WHERE MERID = ? ");
    									spbupopstmt.setString(1, request.getParameter("MacKeyID"));
    									spbupopstmt.setString(2, merid);
    									spbupopstmt.executeUpdate();
    									aaa.set("SPBUPOP_Enable", "1");
    									aaa.set("MacKeyID_4", request.getParameter("MacKeyID"));
    								} else {
    									System.out.println("change SPBUPOP status = L !");
    									spbupopstmt = spbupop_conn.prepareStatement(
    											"UPDATE B2BMERCONFIG SET STATUS = 'L' WHERE MERID = ? ");
    									spbupopstmt.setString(1, merid);
    									spbupopstmt.executeUpdate();
    									aaa.set("SPBUPOP_Enable", "0");
    								}
    							} catch (Exception e) {
    								System.out.println("Exception : " + e);
    								out.println((e.getMessage()));
    							}
    						} else {
    							System.out.println("no SPBUPOP data!");
    							 if ("1".equals(request.getParameter("SPBUPOP_Enable"))){
    									try {
    										pstmt = con.prepareStatement(
    												"INSERT INTO TPMERRISK ( MERID, RISKID, ENABLE ) VALUES ( ?,'SPBUPOP','1')");
    										pstmt.setString(1, merid);
    										pstmt.executeUpdate();
    									} catch (Exception e) {
    										System.out.println("Exception : " + e);
    										out.println((e.getMessage()));
    									}
     
     
    									try {
     
    										System.out.println("add SPBUPOP_STATUS  !");
     
    										pstmtt = conn.prepareStatement("select * from B2BMERMAPPING where MERID=?");
    										pstmtt.setString(1, merid);
    										rs = pstmtt.executeQuery();
    										if(rs.next()){
    											aaa.set("AcqMerID_4", rs.getString("ACQMERID"));
    											aaa.set("AcqTerminalID_4", rs.getString("ACQTERMINALID"));
    											mid = rs.getString("ACQMERID");
    											tid = rs.getString("ACQTERMINALID");
    										}
     
    										System.out.println("mid : " + mid);
    										System.out.println("tid : " + tid);
     
    										spbupopstmt = spbupop_conn.prepareStatement("INSERT INTO B2BMERCONFIG "
    						    					+ "( MERID, MERNAME, MERNUM, PUBKEY, MERTYPE, "
    						    					+ "CURRENCY, SETTLEHOUR, CUTOFFMONTH, CUTOFFDAY, "
    						    					+ "AUTOSETTLE, SETTLENUMS, AUTOTERM, STATUS, MACKEY ) VALUES ( ?,?,?,'Public_Key','SSL','901',?,'P',0,'N',0,'N','A',? )");
     
    										spbupopstmt.setString(1, aaa.get("MerID_1"));
    										System.out.println(aaa.get("MerID_1"));
    										spbupopstmt.setString(2, request.getParameter("mername"));
    										System.out.println(request.getParameter("mername"));
    										spbupopstmt.setString(3, aaa.get("MerID_1"));
    										System.out.println(aaa.get("MerID_1"));
    										spbupopstmt.setString(4, request.getParameter("SettleHour"));
    										System.out.println(request.getParameter("SettleHour"));
    										spbupopstmt.setString(5, request.getParameter("MacKeyID_4"));
    										System.out.println(request.getParameter("MacKeyID_4"));
    										spbupopstmt.executeUpdate();
    										System.out.println("INSERT INTO B2BMERCONFIG OK !");
     
     
     
    										spbupopstmt = spbupop_conn.prepareStatement(
    												"INSERT INTO B2BMERMAPPING ( MERID, ACQUIRERID, ACQMERID, MCCCODE,ACQTERMINALID ) VALUES ( ?,'888888',?,'4011',?)");
    										spbupopstmt.setString(1, aaa.get("MerID_1"));
    										spbupopstmt.setString(2, aaa.get("AcqMerID_4"));
    										spbupopstmt.setString(3, aaa.get("AcqTerminalID_4"));
    										spbupopstmt.executeUpdate();
    										aaa.set("SPBUPOP_Enable", "1");
     
     
    										System.out.println("INSERT INTO B2BMERMAPPING OK !");
     
    									} catch (Exception e) {
    										System.out.println("Exception : " + e);
    										out.println((e.getMessage()));
    									}
     
     
     
    								}
    								System.out.println("update SPBUPOP status end !");
    						}
    					}
     
    				} catch (Exception e) {
    					System.out.println("Exception : " + e);
    				}
    Last edited by Norm; December 7th, 2023 at 09:09 AM. Reason: added code tags

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why I need to clicked the update button twice to save my data to database?

    Where is the update button defined?
    What is printed on the console when the code is executed? Please copy the contents of the console and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: September 16th, 2014, 01:36 PM
  2. Button to save data in text fields to a File
    By puuts in forum What's Wrong With My Code?
    Replies: 10
    Last Post: May 24th, 2013, 10:07 AM
  3. When a button is clicked: get my Data!!!
    By aStudentofJava in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: March 15th, 2012, 08:45 AM
  4. button update when clicked
    By prettynew in forum AWT / Java Swing
    Replies: 4
    Last Post: March 13th, 2011, 04:47 PM