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 3 of 3

Thread: Changing update query in SQL

  1. #1
    Junior Member
    Join Date
    Jul 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Changing update query in SQL

    Basically in this image when I enter the account number the balance will be found, that part is okay. Now when it comes to deposit, I want it to take the existing Account balance and update the table with the deposit amount entered. How do I change the update query according to that?

    Here's my code for the find button

    private void btnFindActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    try
    {
    PreparedStatement stmt=con.prepareStatement("select * from Customer_Details where AccountNumber=?");
    stmt.setString(1,txtMAccNo.getText());


    ResultSet rs=stmt.executeQuery();

    if (rs.next())
    {

    txtMAccBalance.setText(rs.getString("AccountBalanc e"));
    JOptionPane.showMessageDialog(null, "Customer Found");
    }

    else
    {
    JOptionPane.showMessageDialog(null,"Customer not Found.","CustomerDetails",JOptionPane.ERROR_MESSAG E);
    }



    }

    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,"Error encountered while entering data in the database: " +ex, "CustomerDetails",JOptionPane.ERROR_MESSAGE);
    }
    }
    Attached Images Attached Images

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Changing update query in SQL

    where is your update query?
    Whatever you are, be a good one

  3. #3
    Junior Member
    Join Date
    Jul 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Changing update query in SQL

    Quote Originally Posted by John Joe View Post
    where is your update query?
    lol it isn't bro, this is my query. I know I have to change something in the update bracket but I just dont know what. I also have to include the deposit variable somewhere.




    private void btnDepositActionPerformed(java.awt.event.ActionEve nt evt) {
    // TODO add your handling code here:
    try
    {
    PreparedStatement statUpdate=con.prepareStatement
    ("update Customer_Details set AccountBalance=? where AccountNumber=?");



    statUpdate.setString(1,txtMAccBalance.getText());
    statUpdate.setString(2,txtMAccNo.getText());

    // call executeUpdate to execute our sql update statement
    int rowsAffected=statUpdate.executeUpdate();
    if(rowsAffected>0)
    {
    JOptionPane.showMessageDialog(null,"Data Updated..");
    }
    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,"Error encountered while updating data in the database: " +ex, "ManageTransaction",JOptionPane.ERROR_MESSAGE) ;
    }

Similar Threads

  1. Help - Java and Update Query
    By mija in forum JDBC & Databases
    Replies: 3
    Last Post: January 22nd, 2013, 08:34 PM
  2. SQL Query
    By mija in forum JDBC & Databases
    Replies: 13
    Last Post: December 20th, 2012, 07:23 PM
  3. UPDATE SQL QUERY by getting user variables
    By bondage in forum JDBC & Databases
    Replies: 5
    Last Post: April 22nd, 2011, 03:44 PM
  4. update query is firing first then insert query
    By salmondavid88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2011, 10:15 AM
  5. SQL query not working
    By mjpam in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 28th, 2010, 05:15 PM