• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

update query

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k i will try
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but its working correctly with Postgre SQL i.e. my database
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic