This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes Problem with the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with the "where" query." Watch "Problem with the "where" query." New topic
Author

Problem with the "where" query.

Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
Hi,
I'm developing a small module and i'm facing a simple problem which i'm not able to solve.
I've to update my databse using the inputs from a JSP page.
the code for the updation is as follows:


now in the line:

when i'm giving a constant after the "where" clause its working completely fine. But when i'm sending a variable using
or any other method its not working properly and is redirecting back to the jsp page to enter the details to be updated.

Please help
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What does oldusernme contain ? Did you try to debug it ? I see you have a setter method with a funny name : void OldUsername(String value). Shouldn't this be void setOldUsername(String value) ?


[My Blog]
All roads lead to JavaRanch
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
The oldusernme contains the user name that has to be updated. The update option gives us the facility to change the user name as well.

I've corrected the mistake and now it is void setOldUsername(String value)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Debug updateString. What does it contain ?
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
i'm not using any IDE or editor. i'm using simple notepad. So i dont have any idea as to how to debug it.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

It's ok. Use System.out.println(updateString); , and check the output logs.
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
Can you suggest me where to use the System.out.println(updateString);

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You have to check the content of the SQL, so :
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
The problem is that the page gets redirected to either the update page or the gets directed to the page that has to be opened after the success of the operation. So i'm not able to see anything thats being printed. I need to hold the page from getting redirected.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Are you sure ? Did you check the logs ? I'm not talking about the web browser. Check the logs of your web container.
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
This is what it is showing in the logs:
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Well, it looks fine Do you still have a user whose username is 'deepti' in your database ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I think I smell the problem. You first executed :

This updated the 'deepti' user's username to a new name. Now there is no user called 'deepti' anymore. As I said in my previous post, check the database.
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
Its working fine when i'm passing a constant after the where clause. But i need to pass a variable instead. I mean the code is:



its not working then and the log shows:


see.. its not passing the oldusername to the database
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

That's a new step towards the solution oldusernme is null. Which means that setOldUsername is probably not called. You are using struts. What is the name of the input textfield ? Can you post your jsp file (or whatever file it is) as well ?
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
ya sure.

This is my JSP file from where i'm sending the inputs:


and this is the JAVA file:
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Your field is called "oldusername", so the getter/setter should be respectively called getOldusername and setOldusername (note that the 'u' is not capitalized).
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
I made the changes you suggested... but its still not working.

I am unable to give you the log since there is some problem with it and its not responding
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Deepti Gupta wrote:I made the changes you suggested... but its still not working.

I am unable to give you the log since there is some problem with it and its not responding


Mmmhh... Restart the web container.
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
I did.. I even restarted my machine twice...
but still its not responding.
The problem started after I used the System.out.println statement for checking the value of the password for the login page. The login pages is not logging after that and it is taking time to load that finally i have to cancel the process.
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
I just solved the problem with my log.

now it is:


The problem still remains
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

After opening the log file, did you leave it open ? If yes, close it.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Also, make the setOldusername public :
Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
The problem is still there:

Deepti Gupta
Ranch Hand

Joined: Jul 22, 2010
Posts: 30
solved....


Thanks...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I'm glad it's fixed.
 
wood burning stoves
 
subject: Problem with the "where" query.
 
Similar Threads
missing return statement {
Struts 2- Database Connectivity
Struts 2 -Eclipse
Null pointer exception in con.createStatement();
STRUTS 2 "package com.opensymphony.xwork2" does not exist