Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update query

 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what does happen? It Doesnt Work Is Useless
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now today when i again run the program it gives a new error
the error log is here




 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry again Tom for so late reply

actually i have change the code so the code is





the error is :



 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k i will try
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditi agarwal wrote:




Sounds like you have a problem with your SQL query.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but its working correctly with Postgre SQL i.e. my database
 
Joe Ess
Bartender
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is the difference between the query in your code and the query you run against the database?
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have done all same but still its not working what could be the problem now ?
 
Joe Ess
Bartender
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic