Why the data inserted two times into the DB?

Hai all,
When I press the submit button in my form the data will be inserted two timesinto DB. Please help me.
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import com.vguss.bean.RegisterInfoBean; import com.vguss.helper.Out; public class InsertRegInfo { public static Connection connection = DBConnection.getDBConnection(); public static void insertRegData(RegisterInfoBean bean) { Connection connection = DBConnection.getDBConnection(); String loginID = bean.getLoginId(); try { PreparedStatement pst = connection .prepareStatement("SELECT login_id FROM login_details WHERE login_id = ?"); pst.setString(1, loginID); ResultSet set = pst.executeQuery(); if (!set.next()) { insertData(bean); } } catch (SQLException e1) { e1.printStackTrace(); } } private static void insertData(RegisterInfoBean bean) { try { PreparedStatement ps = connection .prepareStatement("INSERT INTO login_details (login_id, password, profile_created_by, security_question, answer, full_name, receive_sms, show_details, agree_terms, register_on) VALUES (?,?,?,?,?,?,?,?,?,now())"); ps.setString(1, bean.getLoginId()); ps.setString(2, bean.getPassword()); ps.setString(3, bean.getProf_created_by()); ps.setString(4, bean.getSecurity_Question()); ps.setString(5, bean.getAnswer()); ps.setString(6, bean.getFullName()); ps.setString(7, bean.getLikeSMS()); ps.setString(8, bean.getShowDetails()); ps.setString(9, bean.getAgreeToTerms()); ps.executeUpdate(); PreparedStatement pstmt = connection .prepareStatement("INSERT INTO user_profile (login_id, gender, email, date_of_birth) VALUES (?, ?, ?, ?)"); pstmt.setString(1, bean.getLoginId()); pstmt.setString(2, bean.getGender()); pstmt.setString(3, bean.getEmailID()); pstmt.setString(4, bean.getDateOfBirth()); pstmt.executeUpdate(); /* insert login id to preferred_partner table */ PreparedStatement pStmt = connection .prepareStatement("INSERT INTO preferred_partner (login_id) VALUES(?)"); pStmt.setString(1, bean.getLoginId()); pStmt.executeUpdate(); } catch (SQLException e) { Out.err(e); } } }

The most obvious thought is that you have a duplicate login id.
You're trying, but I would not consider this to be well written code, for these reasons:
1. You don't close any JDBC resources in finally blocks - no connections, no statements, no result sets. Search the forum for people with "max open cursors exceeded" to see why this is a bad idea.
2. You create a static Connection in this class, but nobody closes it. Classes that execute SQL should not be responsible for obtaining connections; a Connection should be provided to them. Transactions are the reason: a class executing SQL can't know if it's involved in a unit of work with other classes. Somebody who knows the use case and the transaction boundaries ought to be getting the Connection, handling commit/rollback, and closing the Connection.
3. Refactor that INSERT into three methods. You'll be glad you did someday.
4. Your INSERT method looks like it's doing a security check, too. Isn't it a little late for that? If you must, move that code into a separate method that returns a boolean. A well-designed method does one thing well. Yours is doing two.
5. The common JDBC idiom isn't "if (!set.next())", it's "while (set.next())". It's good to use common idioms, because it makes it easier for other people to understand your code.
But see if you have a repeated login ID.
And step through in a debugger to see what's going on.
%

Similar Messages

  • Combine the data of two DSOs into one

    Hello experts,
    how to load the data of two DSOs into a single one using transformations and DTPs?
    Example:
    DSO A keyfields: X,Y,Z / attributes M,N,O
    DSO B keyfields: X,Y,Z / attributes P,Q
    DSO C keyfields: X,Y,Z / attributes M,N,O,P,Q  (result should be a single data record!)
    In the transformation between DSO A and C I map all keyfields and attributes M,N,O (no mapping for P and Q, meaning no transformation rule). For B to C mapping is all keyfields and attributes P, Q (no mapping for M,N,O, no transformation rule).
    When I now load the data of DSO A and DSO B to DSO C I either see the attributes M,N,O or P,Q. This means that only the latest DTP is available and overwrites the attributes with blank values of the first DTP.
    I have a solution using ABAP coding but according to the SAP Training courses (BW330) it should work without using ABAP coding.
    Any help is highly appreciated.
    Thanks in advance.
    Marco

    Hi Marco,
    Thanks again
    I looked into BW330 Business information warehouse - Modelling.
    Course version : 2006 Q2
    Material number : 50079531
    I looked into the page 281 still no luck.
    just an overview i need to create X,Y,Z,M,N,O as info objects characteristics
    and P, O  as infoobjects keyfigure.
    None of them will have attributes and i load XYZMNO to DSO1 and same XYZPO to DSO2.
    Then map DSO1 - DSO3 and  DSO2 - DSO3 and carry out the steps to get the data from DSO1 and DSO2 to DSO3.
    Am i right.
    Regards,
    Harish

  • How to merge the data from two cubes into ODS?

    Hi,
    I wan to analyze the data of both the cubes by means of merging into an ODS.
    And i want to have one of the characteristic is used as a key for the purpose which is existing in both the cubes
    Cany nay one detail me of how this can be done?
    Thanks,
    Ravi

    Hi,
    If it is very needful.
    you can create the ODS object for each infocubes and map these ODS objects to target ODS object.
    or, you can create the Export datasources from each infocube and map these to new target ODS object which is having all the char and KF of both the infocubes.
    reg.
    Vis

  • Data inserting two times in a table  when i click submit button

    Hi Experts,
    I had a problem, when i am inserting data in a table from a form at the first time when i click button it adds two times, afterwards it is adding one time only, the form and table are from same value node (table is collection cardinality : 1..n and selection cardinality is 0..n) i don't understand why it  is happening here?
    Regards,
    Pradeep Kumar

    Hi Pradeep,
    Please check the method for inserting data in a table. May be method is called two times.
    Post your code here to look into it.
    Best Regards,
    Arun Jaiswal

  • Getting the dates I have input into the right order?

    I am new to numbers and accounting so am workingon a simple expenditure spreadsheet.
    When I put in the dates which I have amended to the american model month/date/year not uk date/month/year... in this way 12.03.2009 meaning march 12th 2009.
    all the dates run in perfect order except they miss out the year part meaning my account for year 2009- 2010 have dates all jumbled up for example...
    01.08.2009
    01.13.2009
    01.13.2009
    01.19.2010 jan 19th 2010
    01.20.2009 jan 20th 2009
    01.21.2010
    01.22.2009
    01.22.2010
    how do I amend this so that the dates run consecutively and in year groups too?
    I have tried in inspector and system preferences to no avail.
    I am grateful for any help... as I am wasting valuable time on such a simple thing... and working out very fast that my accounts reveal an ever decreasing loss during my 2nd year of trading!!! of which I am quite proud!

    Hi re-d,
    Welcome to Apple Discussions and the Numbers '08 forum.
    Your 'dates' are not being recognized as dates by Numbers, probably because you have entered them in a format not recognized as a Date format, and are being correctly sorted as Text.
    From page 57 of the Numbers User Guide:
    *Working with Dates in Cells*
    Unless a cell has a date and time format associated with it, when you type a value that
    can be interpreted as a date or time value, Numbers might reformat the value.
    For example, if you type 1/22/45 or 1-22-45 into a table cell with the Automatic cell
    format and leave the cell, the value changes to Jan 22, 2045. If you enter a 2-digit year
    value greater than or equal to 50, Numbers adds the prefix “19”; otherwise Numbers
    adds the prefix “20.”
    And if you type 12 pm, the value becomes 12:00 PM. You can edit the value if you need
    to change it.
    +See “Using the Date and Time Format” on page 62 to learn about the date and time+
    format.
    You'll find the Numbers User Guide, supplied with your copy of iWork '08, in the Help menu in Numbers.
    Regards,
    Barry

  • How to read the data file and write into the same file without a temp table

    Hi,
    I have a requirement as below:
    We are running lockbox process for several business, but for a few businesses we have requirement where in we receive a flat file in different format other than how the transmission format is defined.
    This is a 10.7 to 11.10 migration. In 10.7 the users are using a custom table into which they are first loading the raw data and writing a pl/sql validation on that and loading it into a new flat file and then running the lockbox process.
    But in 11.10 we want to restrict using temp table how can we achieve this.
    Can we read the file first and then do validations accordingly and then write to the same file and process the lockbox.
    Any inputs are highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

    Hello Gurus,
    Let me tell you about my requirement clearly with an example.
    Problem:
    i am receiving a dat file from bank in below format
    105A371273020563007 07030415509174REF3178503 001367423860020015E129045
    in this detail 1 record starting from 38th character to next 15 characters is merchant reference number
    REF3178503 --- REF denotes it as Sales Order
    ACC denotes it as Customer No
    INV denotes it as Transaction Number
    based on this 15 characters......my validation comes.
    If i see REF i need to pick that complete record and then fill that record with the SO details as per my system and then submit the file for lockbox processing.
    In 10.7 they created a temporary table into which they are loading the data using a control file....once the data is loaded into the temporary table then they are doing a validation and updating the record exactly as required and then creating one another file and then submitting the file for lockbox processing.
    Where as in 11.10 they want to bypass these temporary tables and writing it into a different file.
    Can this be handled by writing a pl/sql procedure ??
    My findings:
    May be i am wrong.......but i think .......if we first get the data into ar_payments_interface_all table and then do the validations and then complete the lockbox process may help.
    Any suggestions from Oracle GURUS is highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

  • HT4796 Purchased Imac 21.5 in December. Today I was migrating file by following the directions as sated on the imac. Down loaded the migration assistance. two hours into the down load with 25% of the files moved to the  to the Imac the system disconnected

    I need to restart the down load of files from my xp hp to the imac. The imac is frozen on transferring your information screen and the HP is looking for the Imac.
    Can anyone help me with retarting this process. Thanks, Bill

    This is what I find truly baffling and frustrating, that other people with the same problem are having the issue resolved without hesitation. And I've been going through this for 3 months now.
    I did receive a call last Wednesday, 10 Nov. from customer relations, they have finally agreed to replace the screen .. but .. she told me it isn't being replaced under warranty, it was her personal decision, an act of good will, because they value me as a customer ... which is good news, but I find their reasoning rather patronising and a kind of 'round about' way of addressing the problem without admitting to fault on their side.
    She also told me that they would only replace the screen this one time only and they couldn't guarantee that the replacement part wouldn't have a similar problem, and if it does then that's too bad ... and this is after they argued that the problem isn't due to a faulty part. The contradiction has been noted and filed!
    So .. I was advised to contact the retailer on 12 Nov to arrange taking the iMac in for repair, I waited until the afternoon of that day, and when I called them I was told they hadn't heard anything from Apple, and that their technician was on holidays for another week. I know they have 2 or maybe even 3 technicians there. I didn't say anything at the time as I wanted to keep things 'friendly' in order to get the job done, but I'm noting everything in writing, and if no further progress is made by next Friday (when the tech is due to return) then more calls will be made and letters will be sent.
    If I do need to contact them again I will take your advice iMacMan2010 and ask to speak to someone else, preferably higher up the chain.
    I'm glad that a resolution is now looking close, but wont be satisfied until I see the repaired computer sitting on my desk. And even then I'll have serious doubts about making any future Apple purchases.

  • Why the iPhone vibrates 2 times when the iPhone OS is starting?

    Someone know why the iPhone vibrates two times when the iPhone OS is starting (and the apple logo appears)
    In my case, this rare event occurs when a problem with an application (3rd party) force to iPhone to restart or when occurs a problem during the sync with iTunes. After this event, my iPhone never load (your OS) and the only way is the restore.
    null

    Amazing how much trouble when can get into by taking shortcuts before we understand something... isn't it....
    Read the API and find out for yourself what events are triggered by a JButton......
    Remember thsi advices:
    1) Before using shorthand event handling, make absolutely sure that you understand the process back to front...
    2) Write your own event, listener and implementer in order to get a clearer picture...
    3) Until this is clear to you, always implement the appropriate listener and override the necessary methods....

  • How to store the data of a file into an ArrayList?

    Hi! everyone.
    I want to know
    if I have a File, and the data in the file are type int, type String...
    And I have a ArrayList which is of type Question
    How do I store the data of that file into the ArrayList
    I tried to use the while loop(use the hasNextLine() to read the data line by line)
    But I cannot add data which are not of type Question to the ArrayList.
    Can you tell me what I should do, please?
    I also wonder that
    The data of the file are of many types, but when I try to read it with the nextLine(), the data all turn out to be of type String. Why?
    Thank you.
    Edited by: Terry001 on Apr 30, 2008 1:13 PM

    No, a line in the file is just part of a question
    The format of the file is like this:
    *<question type code>                    :     String*
    *<question point value>                    :     int*
    *<question category>                         :     String*
    *<question difficulty level>               :     int*
    *<question text>                              :     String*
    *<question correct answer>               :     String*
    *<optional question-specific data>     :     String*
    *<question terminator>                    :     String*
    And here is an example
    TF //TrueFalseQuestion
    5 //points value
    None //category
    3 //difficulty level
    The capital of the United States is Washington, D.C. //question text
    True // answer
    *** //quetion terminator
    I created an ArrayList in the Test class:
    private ArrayList<Question> questions; // Create inside constructor
        public Test (String name, String instr)
            testName = name;
            scoreEarned = 0;
            scorePossible = 0;
            instructions = instr;
            questions = new ArrayList<Question>(); //[MAX_NUMBER_OF_QUESTIONS];
        }And I tried to use the following method to store the data of the file to the ArrayList
    // This method loads a set of questions from a plain text file
        public void loadQuestionsFromFile(String fileName) throws FileNotFoundException
            try
                File fileReader = new File("input.txt");
                Scanner sc = new Scanner(fileReader);
                while (sc.hasNextLine())
                    // I don't know how to pass the data I got from the nextLine() method to the ArrayList because they are of different type
            catch (FileNotFoundException a)
                System.out.println(a);
        }    As all you said, I should create an Question object in the while loop
    Question temp = new Question ();But I have no idea how to pass the int and String to the Question object.
    Thank you

  • Synchronizing the read of two timer tasks (Period and Two Edge Separation)

    Hello,
    I am using labview 2011 and need to latch the data from two timer tasks of a 6602 board at the same time and then perform the read. One task is a period measurement the other is a two edge speration.  It sounds pretty simple and I am sure it is, I just haven't located the correct information yet,  If someone would point point me in the correct direction.
    Thanks,
    Mike

    While it's true that a digital edge arm start trigger can help to sync the tasks to begin together, the nature of the measurements you're making also have a big impact on whether you can depend on the buffered data remaining "synced."   Both measurement types will latch measurement data at times determined by the signal(s) being characterized.  You cannot configure either task type to sample at a known constant rate.  You can only accept samples at the rate dictated by the signals' own edges.
    Ok, so having said all that, here are some implications:
    1. a cumulative sum of all your period data will effectively give you timestamps for all the active edges, with t=0 set by the arm start trigger edge.
    2. there is no information inherent in a two edge separation measurement that can identify the time relative to the arm start trigger.  You'll get a bunch of measured interval times with completely unknown times between those intervals
    3. caveat: if you are somehow using the same signal edge for both measurements AND getting one measurement of two-edge separation for each and every period measurement, ONLY then would you be able to reconstruct the timestamps relative to the arm start trigger edge.
    So I'd caution you that the idea of latching readings in sync or reconstructing relative edge times between the measurements is pretty unlikely to work except under some very specific circumstances.
    -Kevin P

  • Retrive data from two tables into one internal table.

    Hi SDN,
    I am downloading the Assets data from two tables ANLA,ANLZ.
    there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
    can you please send me the SELECT Syntax for this probl.....
    Thank you & Regards,
    Manoj

    Hi manoj,
    Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
    data: begin of itab occurs 0,
            BUKRS like anla-BUKRS,
            ANLN1 like anla-ANLN1,
           BDATU like anlz-BDATU,
            end of itab.
    select anlabukrs anlaANLN1 anlzBDATU  into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
    Please come back for any clarification.
    Thanks and Regards,
    saurabh

  • Extract Time from date and Time and Need XLMOD Funtion to find the Difference between Two Time.

    X6 = "1/5/15 5:16 AM" & NOW ....................difference by Only Time
    not date
    X6 date and Time will be changing, Its not Constant
                Dim myDateTime As DateTime = X6
                Dim myDate As String = myDateTime.ToString("dd/MM/yy")
                Dim myTime As String = myDateTime.ToString("hh:mm tt")
                Dim myDateTime1 As DateTime = Now
                Dim myDate1 As String = myDateTime1.ToString("dd/MM/yy")
                Dim myTime1 As String = myDateTime1.ToString("hh:mm tt")
    Need to use this function to find the Difference between Two Time. due to 12:00 AM isuue
    Function XLMod(a, b)
        ' This replicates the Excel MOD function
        XLMod = a - b * Int(a / b)
    End Function
    Output Required
     dim dd  = XLMod(myTime - myTime1)
    Problem is myTime & myTime1 is String Need to convert them into Time, Later use XLMOD Funtion.

    Induhar,
    As an addendum to this, I thought I'd add this in also: If you have two valid DateTime objects you might consider using a class which I put together a few years ago
    shown on a page of my website here.
    To use it, just instantiate with two DateTime objects (order doesn't matter, it'll figure it out) and you'll then have access to the public properties. For this example, I'm just showing the .ToString method:
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    Dim date1 As DateTime = Now
    Dim date2 As DateTime = #1/1/1970 2:35:00 PM#
    Dim howOld As New Age(date1, date2)
    MessageBox.Show(howOld.ToString, "Age")
    Stop
    End Sub
    End Class
    I hope that helps, if not now then maybe at some point in the future. :)
    Still lost in code, just at a little higher level.
      Thanx frank, can use this in Future....

  • Converting Delivery Creation Date/Time into the Local Date/Time

    Hi
    I have two fields like 'Delivery Creation Date' and 'Delivery Creation Time' in ECC system . My user wants the Delivery Creation Date / Delivery Creation Time in Local time of Plants .
    For example :
    Delivery    Plant       DelivCreationDate       DelivCreationTime   DelivCreationDate(Local)   DelivCreationTime(Local)
    312456          1650               11/2/2007                     4:30                          11/2/2007                          3:30
    Here the Plant 1650 is in Mexico . The above delivery is created in Canada in ECC system according to the candain time .
    But user wants to convert the Candain Delivery Creation Date and Time into the Local Date/Time of specific plant .
    So we need to convert the  Candain Delivery Creation Date and Time into Mexico timings .
    How can it is possible this one and user wants to automate this process .
    Please let me know
    Mubeen

    DATA :
    timestamp like TZONREF-TSTAMPS,
    time like sy-uzeit,
    date like sy-datum.
    The following function module is used to convert the
    time and date into GMT timestamp
    CALL FUNCTION 'IB_CONVERT_INTO_TIMESTAMP'
    EXPORTING
    i_datlo = <source_fields>-delivery_date
    i_timlo = <source_fields>-delivery_time
    I_TZONE = CAD'
    IMPORTING
    E_TIMESTAMP = timestamp.
    The following function module is used to convert the
    above obtained timestamp to MEX  timezone date and time.
    CALL FUNCTION 'IB_CONVERT_FROM_TIMESTAMP'
    EXPORTING
    i_timestamp = timestamp
    I_TZONE = MEX
    IMPORTING
    E_DATLO = date
    E_TIMLO = time.
    CAD and MEX are variables i have used...
    the challenge is to find the canadian and mexican time zone....CAD and MEX.
    which you can get by performing a lookup in table T001W and passing country as parameter.

  • Why does my mac mini's mouse show a pinwheel every time I hover over the date area? Also, sometimes the date shows up incorrectly.

    Why does my mac mini's mouse show a pinwheel every time I hover over the date area? Also, sometimes the date/time shows up incorrectly. It started happening after I updated to OS X Mountain Lion.

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left.
    Click the Clear Display icon in the toolbar. Try the action that you're having trouble with again. Post any messages that appear in the Console window – the text, please, not a screenshot.
    When posting a log extract, be selective. In most cases, a few dozen lines are more than enough.
    Please do not indiscriminately dump thousands of lines from the log into a message.
    Important: Some private information, such as your name, may appear in the log. Edit it out by search-and-replace in a text editor before posting.

  • How to insert the data which is present in the variable into the table

    Hi,
    Let's consider that I have one table and I have stored the table column names in one variable and their values in another variable.
    I want to insert the data that is present in the variables into the table.
    I tried the following way :
    Declare
    V_columns    Varchar2(50) := 'Empno';
    V_values       Number(10) := 101;
    Begin
    Insert Into Emp (V_columns) Values (V_values);
    End;
    The above procedure gives an error : PL?SQL : ORA-00904 : "V_COLUMNS": invalid identifier
    Using the Execute Immediate, we can insert the data which is present in the variables into the table.
    Is there any other way to insert the data which is present in the variable into the table..?
    Can anyone please give me the solution..?
    Thanks..

    plz use this...
    DECLARE
       v_columns   VARCHAR2 (50) := 'Empno';
       v_values    NUMBER (10)   := 101;
    BEGIN
       EXECUTE IMMEDIATE    'Insert Into Emp ('
                         || v_columns
                         || ') Values ('
                         || v_values
                         || ')';
       COMMIT;
    END;

Maybe you are looking for

  • HP LaserJet Pro MFP M225dw SMTP serwer error

    Hello I have problem with scannig to email from me new HP LaserJet Pro MFP M225dw, i configured everything and it worked i scanned and meiled a test scan. After 2-3 h i tryed to scan a new document and got error that me SMTP servers don't respond. I

  • Which DVI Connector

    Hi There, I have a T61 in a 2504 docking station. I wish to connect 2 screens - 1 by the normal VGA and the other by the DVI connection. My issue is that I do not know which DVI to buy. DVI-D, DVI-A, DVI-I etc etc. Can someone tell me the correct DVI

  • No type in print box

    there is no type in the print dialog box when  i try to print a document out of reader 10.1.2

  • Can't open gmail

    I've been having this problem, which sounds a little similar to some other peoples problems trying to access gmail with Firefox. https://mail.google.com/intl/en/mail/help/about.html From that web page, clicking the sign in button does absolutely noth

  • My External Editor is Not Working!

    I have CS3 and Fireworks CS3, recently upgraded from Macromedia 8 suite.  Now when I try to access Fireworks CS3 from DW I get an error message. I did check the preferences panel to make sure that I've specified Fireworks as the primary editor with t