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 8817023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:45:07+00:00 2026-06-14T04:45:07+00:00

Beginner’s question: I’m trying to manipulate tuples from two different attributes in a relation

  • 0

Beginner’s question: I’m trying to manipulate tuples from two different attributes in a relation using Java to process the SQL (for a university non-assessed practical).
I have a relation with four attributes, including the name of a type of coffee, the sales it has that week and the total sales of the coffee.

The code I am trying to create will update the sales and the total fields with new figures. It is meant to take both totalSales and Sales arrays, add them, then update both attributes in the relation accordingly.

This is my code so far (I’ve cut out all obvious/unnecessary code):

String updateTotalString = "update COFFEES set TOTAL = ? set SALES = ? where COF_NAME = ?";

String [] coffees = {"Columbian", "Earl Grey", "Kenyan", "Nescafe"};
int [] totalSales = {400,650,340,1000};
int[] sales = {50,75,100,100};

updateTotal = con.prepareStatement(updateTotalString);
    for (int i = 0; i < len; i++)
    {
        updateTotal.setInt(1, (sales[i] + totalSales[i]));
        updateTotal.setInt(2, sales[i]);
        updateTotal.setString(3, coffees[i]);
        updateTotal.executeUpdate();
    }

Unfortunately, running this gives me an SQL syntax error, focusing on the first line (the String updateTotalString). I have a feeling it’s to do with the fact I’m trying to do two sets in one line and have got the syntax wrong.
Can anybody help me out?

  • 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-14T04:45:08+00:00Added an answer on June 14, 2026 at 4:45 am

    use , instead of multiple SET

    String updateTotalString = "update COFFEES set TOTAL = ?, SALES = ? where COF_NAME = ?";
    

    the basic syntax of update is

    UPDATE tableName
    SET colA = '',
        colB = '', .....
    WHERE ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner question... How different is define($a,365); from $a = 365; ? Thanks! JDelage
Beginner question perhaps: I'm trying to check my user permissions from facebook with Koala.
Beginner rails question: How does one return a file from a controller in rails?
Beginner question here: I'm trying to understand the some basic memory management. if I'm
Python beginner here. I am using the matplotlib library to make graphs from tab
Definitely a beginner question... basically, I want to have the same design from this
Beginner java question, but I cannot understand how call-by-Value ( or Reference ) is
Beginner jquery question. I am using the Tokenizing Autocomplete Text Entry plugin, with the
RoR beginner here using rails 3.2.3 and ruby 1.9.3 Currently I am trying to
Beginner here trying to get a pipeline working in bash. If somebody can see

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.