Get your CodeRanch badge!*
The moose likes JDBC and the fly likes How to update SQL databse table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to update SQL databse table" Watch "How to update SQL databse table" New topic
Author

How to update SQL databse table

sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
I want to update all the datas of one of the column of a table in my SQL database. I am using cpanel tool to manage/keep a track of my database.I exported the data in an excel sheet/CVS and have already modified it .How do I import the sheet back into that table such that it updates just that column.
I have to manage my site.Kindly let me know asap.

Thanx
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not really a JDBC question, however: what database do you use? Can't you just use SQL directly to update you data? Why do you export your data first?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
I want to update my column say(phone-number) for all the cusomers.How can i change all the phone numbers by running just one query.So I exported it in the form of an excel/cvs sheet & then easily modified the column & now how do i import it back so that just that column is modified.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Fair enough - you can't do that with just one statement (unless you are changing every 'phone number to be the same). Obviously, you could do it with a bunch of SQL statements though.

I still can't help much more though, unless you tell us which database you are using.
sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
Thanx Peter for ur immediate reply..Okay can u help me out with this...

what is the query to update a column of a table by 5%
e.g:
Tablename roduct
Column name : Sale

So now I want to update Sale column by 5% so there is a query to do that.
Kindly let me know as I am getting error with this one:

UPDATE table Product SET Sale = ((Sale * 5)/100);
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Originally posted by sunita shaw:
So now I want to update Sale column by 5% so there is a query to do that.
Kindly let me know as I am getting error with this one:

UPDATE table Product SET Sale = ((Sale * 5)/100);

Remove the word "table". This is really an SQL question, that doesn't have anything to do with Java or JDBC. You'd better ask this to an SQL expert instead of on a Java forum.

Your SQL statement is going to set the value of column Sale to 5% of the original value, for all rows. Is that really what you want? Or did you want to increase the Sale values by 5% (i.e., set the value to 105% of the original value)?

UPDATE Product SET Sale = ((Sale * 105)/100);
[ December 01, 2005: Message edited by: Jesper de Jong ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29249
    
139

Note that it is perfectly fine to ask SQL questions here. It's even in the forum description! Some people have gotten answers to complex SQL questions in this forum recently.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to update SQL databse table
 
Similar Threads
JTable Problem
Sql operation on mobile
Update using EJB-QL
Can I use prep.execute to update a record?
Hibernate: sql-insert sql-updat sql-delete