aspose file tools*
The moose likes Struts and the fly likes update query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "update query" Watch "update query" New topic
Author

update query

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
Hi friends i am writing an update module but there is some problem which i am nt getting

my update query is not working instead if at this place i use insert query it works

my code is


this is my forgetpasswordaction file

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8903
    
    8

So what does happen? It Doesnt Work Is Useless

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
its an update query so i want to update my database from my struts application
i need that when i change password in form that changes are reflected in the database
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
We need specifics on is what happens when you run this code. Does it write anything to any of your log files? Does it go into that sql exception that you have a catch for? Does it just run the method completely with out updating the database but with out generating an error?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
Sorry for late reply i think the error is not in the update query but somewhere else

its giving an error

The column index is out of range: 1, number of columns: 0.

should i create a new message for it or it will be continue in this only
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
When I get that error, it usually indicates that I am trying to set the value of a bind variable in an sql statement (using something like the psat.setString you have in your code) and I am specifying an index for it that is greater than the number of ? in the string. Your code doesn't appear to have that problem. Can you give the full stack trace of the error, including the line numbers, maybe this is happening some place unexpected.
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
now today when i again run the program it gives a new error
the error log is here




Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Assuming the line numbers in your action class are still the same, it sounds like either psat or forgetpasswdForm.getLoginname() is null at line 49, can you tell which and why?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
sorry again Tom for so late reply

actually i have change the code so the code is





the error is :



Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
My questions from my previous post still apply. All we really know is that you are trying to use a reference that is null on line 49. Can you determine which variable on line 49 is null and why?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
k i will try
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
hi tom i have printed both values & they are not null
i don't know what is happening i am writing action file & error page

action file




error :





thank you

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8903
    
    8

Aditi agarwal wrote:




Sounds like you have a problem with your SQL query.
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
but its working correctly with Postgre SQL i.e. my database
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8903
    
    8

So what is the difference between the query in your code and the query you run against the database?
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
It sounds like you gone back to your earlier problem where you are trying to put a value into the first bind variable in a prepared statement but the prepared statement doesn't have any bind variables.

after this line:

psat=conn.prepareStatement("update ams_login set password='?' where loginname='?';");

try putting in some code to write psat.toString() to your log file, I wonder if the statement isn't being created correctly.

I'm not exactly sure what this will print out, but I read that postgres should write out the text of your prepared statement.

Let us know what it shows.
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
Aditi agarwal wrote:
psat=conn.prepareStatement("update ams_login set password='?' where loginname='?';");
psat.setString(1, forgetpasswdForm.getPassword().trim());
psat.setString(2, forgetpasswdForm.getLoginname().trim());


You did mistake in update query dont use '?' use ? and remove ; from the query.
Let me know if you face any problem.

Regards,
Sriram.V


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thank you sri ramvaithiyanathan for your reply

i would like to ask then what should i write in place of the question marks should i write anything else
or
my query wouldlook like

update <tablename> set password =? where loginname =?


thank you
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
your query should be like this
update tableName set column = ? where column = ?

psat.setString(1,XXX);
psat.setString(2,XXX);

The number 1 and 2 denoted the place of the ?
In XXX pass the value which you want to use in the query.
The XXX value and datatype used in your table should be of same.

Hope it clears your doubt.

Regards,
Sriram.V
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i have done all same but still its not working what could be the problem now ?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8903
    
    8

We cannot possibly know because we cannot see your current code or the errors you are seeing. Please read our FAQ, HowToAskQuestionsOnJavaRanch. The better question you ask, the more help we can be.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: update query