Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8107935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:56:04+00:00 2026-06-06T00:56:04+00:00

dbStatement = con.createStatement(); dbResult = dbStatement.executeQuery(SELECT Vendor_Code FROM temp ORDER BY status ASC );

  • 0
dbStatement = con.createStatement();
dbResult = dbStatement.executeQuery("SELECT Vendor_Code FROM temp ORDER BY status ASC ");

while (dbResult.next())
{
    VendorCode=dbResult.getString("Vendor_Code");
    System.out.println(VendorCode);

    dbStatement.executeUpdate("INSERT INTO temp1 VALUES ('"+VendorCode+"')");
}

In the above code I am selecting a list of vendor code in the ascending order of their status,it works properly if I don’t add:

dbStatement.executeUpdate("INSERT INTO temp1 VALUES ('"+VendorCode+"')");  

into the while loop. If I add this I’m getting result as only the first value which is in the sorted list and also it’s getting inserted into the temp1 table…

I am using Java swing and MySQL in NetBeans. Any idea please why this is happening?

If I do the above code in other way as,

    dbStatement = con.createStatement();
    dbInsert = con.createStatement();
    dbResult = dbStatement.executeQuery("SELECT Vendor_Code FROM temp ORDER BY               status ASC ");

     while (dbResult.next())
             {
                 VendorCode=dbResult.getString("Vendor_Code");


                dbResult = dbInsert.executeQuery("SELECT Bid_No,Vendor_Name,Vendor_Address,Amount,Tax_Percentage,Amount_Aftertax,Expected_Deliverydate,Vendor_Code FROM purchase_bid    where   PE_Number='"+penumber+"' AND Vendor_Code='"+VendorCode+"'  ");


                 while(dbResult.next())

                    {


                      Bid_Number=dbResult.getString("Bid_No");
                      vendor_name=dbResult.getString("Vendor_Name");
                      vendor_address=dbResult.getString("Vendor_Address");
                      Amount=dbResult.getString("Amount");
                      tax=dbResult.getString("Tax_Percentage");
                      date2=dbResult.getString("Expected_Deliverydate");
                      Amount_Aftertax=dbResult.getString("Amount_Aftertax");
                      venCode=dbResult.getString("Vendor_Code");
                      date3=date2.split("-");
                        String day="";
                        String month="";
                        String year="";
                        day=date3[2];
                        month=date3[1];
                        year=date3[0];

                     date=day+"-"+month+"-"+year;
                      addtoCart();//for displaying it in jTable


                   }


              }

It does not take VendorCode in ascending order for retrieving values from purchase_bid table..Then it again takes first sorted value and nothing is displayed in jTable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:56:05+00:00Added an answer on June 6, 2026 at 12:56 am

    You should only use the statement instance for one operation. So calling the executeUpdate-method erases the ResultSet obtained by the executeQuery-method.

    Create a second statement, so that:

    dbStatement = con.createStatement();
    dbInsert = con.createStatement();
    dbResult = dbStatement.executeQuery("SELECT Vendor_Code FROM temp ORDER BY status ASC ");
    
    while (dbResult.next())
    {
        VendorCode=dbResult.getString("Vendor_Code");
        System.out.println(VendorCode);
    
        dbInsert.executeUpdate("INSERT INTO temp1 VALUES ('"+VendorCode+"')");
    }
    

    If you’re not just testing and you actually want to bulk insert the Vendor_Code from temp to temp1, try using INSERT … SELECT

    dbInsert = con.createStatement();
    dbInsert.executeUpdate("INSERT INTO temp1 SELECT Vendor_Code FROM temp");
    

    See the official MySQL documentation for further details on this type of INSERT:
    http://dev.mysql.com/doc/refman/5.1/en/insert-select.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in IndexController.php: $sql = 'SELECT * FROM ?'; $stmt
All this afte rupgrading from 1.4.1 I get a quite specific error message: Next
i have this query that works fine SELECT t.username FROM users t LEFT JOIN
Allright, this is like thousandth time when I get kinda useless information from a
I have a little problem with the Zend_Db_Stmt. This works: $sql = SELECT *
After upgrading magento from 1.4.0.1 to 1.5.1.0 , i'm not able to submit an
ORDER BY is not working properly for numbers,but it's working well if I give
it's a v 1.4.1.1 Magento, upgraded from a v 1.3.2.4 When I try to
Help pls with getting magento attribute while checkbout. I have 'only_registered' attribute. I trying
I have the following code: $selectColumns= array('user_id.user_email', 'user_details.first_name', 'user_details.last_name', 'user_details.zip', 'user_details.store_id'); $result = $handle->select()->from('user_id')

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.