5 Replies - 168 Views - Last Post: 19 July 2019 - 09:55 AM Rate Topic: -----

#1 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Syntax question or deleting an item from a record.

Posted 19 July 2019 - 08:20 AM

Okay so I don't have any code to represent my question, I just need the syntax.

If I have a grocery item table with a name and a price, and I want my program to be able to take in the name of the item but then delete and replace not the name but the price, how do I do it?

I was trying to go in the direction of:

	 try {
			Statement stmt = connTable.createStatement();
			ResultSet rs = stmt.executeQuery("select * from items where item_name = '" +name+"' ;");
			ResultSet rs2;
			String nameHolder = name; 
			if(rs.next()) {
				rs2 = stmt.executeQuery("delete from items where item_name = '" + name + "' and item_price = '" +  ";")
			}



and I was wanting to just delete the name and item price and id replace the name with the nameHolder. But then I realized I'm not even asking the client for the original price, so idk how I would even delete the whole record right? Also, if I did delete the entire record its primary key which is the item_number would also be deleted and that is something I don't want to mess with.

Basically my goal is to edit the price of an item... how please?

Thanks guys! (and gals =] )

Is This A Good Question/Topic? 0
  • +

Replies To: Syntax question or deleting an item from a record.

#2 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Syntax question or deleting an item from a record.

Posted 19 July 2019 - 08:26 AM

View Postdako, on 19 July 2019 - 08:20 AM, said:

Okay so I don't have any code to represent my question, I just need the syntax.

If I have a grocery item table with a name and a price, and I want my program to be able to take in the name of the item but then delete and replace not the name but the price, how do I do it?

I was trying to go in the direction of:

	 try {
			Statement stmt = connTable.createStatement();
			ResultSet rs = stmt.executeQuery("select * from items where item_name = '" +name+"' ;");
			ResultSet rs2;
			String nameHolder = name; 
			if(rs.next()) {
				rs2 = stmt.executeQuery("delete from items where item_name = '" + name + "' and item_price = '" +  ";")
			}



and I was wanting to just delete the name and item price and id replace the name with the nameHolder. But then I realized I'm not even asking the client for the original price, so idk how I would even delete the whole record right? Also, if I did delete the entire record its primary key which is the item_number would also be deleted and that is something I don't want to mess with.

Basically my goal is to edit the price of an item... how please?

Thanks guys! (and gals =] )



will this work: "UPDATE items SET item_price = '" + newPrice +"' WHERE [item_name = '" + name+ "'];"
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15226
  • View blog
  • Posts: 60,944
  • Joined: 12-June 08

Re: Syntax question or deleting an item from a record.

Posted 19 July 2019 - 08:30 AM

So the sql UPDATE command?
https://www.w3school.../sql_update.asp

You would also want to use parameters in your queries.
https://docs.oracle....s/prepared.html
Was This Post Helpful? 1
  • +
  • -

#4 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Syntax question or deleting an item from a record.

Posted 19 July 2019 - 08:35 AM

View Postmodi123_1, on 19 July 2019 - 08:30 AM, said:

So the sql UPDATE command?
https://www.w3school.../sql_update.asp

You would also want to use parameters in your queries.
https://docs.oracle....s/prepared.html

Yeah I can't get it to work yet but I'm gonna mess with it when back from work. If I still can't get it I'll post again but I am probably just making a small error.

It doesn't crash but it just doesn't edit the record.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15226
  • View blog
  • Posts: 60,944
  • Joined: 12-June 08

Re: Syntax question or deleting an item from a record.

Posted 19 July 2019 - 08:38 AM

*shrug* There is a lot of weird going on with that statement.


UPDATE items 
SET item_price = '" + newPrice +"' 
WHERE [item_name = '" + name+ "']


Why is the value for 'item_price' a varchar string? Wouldn't it be a number?
why is there brackets around the where clause?

Then again I don't know what you are connecting to, your table, or reasoning, but so it goes.

You also do not need to quote the post above yours.. or even your own post.
Was This Post Helpful? 0
  • +
  • -

#6 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Syntax question or deleting an item from a record.

Posted 19 July 2019 - 09:55 AM

I got you on the quote thing, I was just clicking the wrong button I suppose. But I got it fixed. Yeah idk, the char thing through me off and I ended up making item_price a text field but I will be changing that. I am just wildly troubleshooting things. Like I said I am going to start reading as recommended. I've read 3 books on c++ but it was a while ago and I never really used it unfortunately.

You did help though so thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1