Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


sql Update format in jsp

Posted on 2004-04-08
Medium Priority
Last Modified: 2010-04-01
What is wrong with the format of this update statement.

String update = "myName";
int num = stmt.executeUpdate("UPDATE members SET password = "+checkPassword+" WHERE fName LIKE "+update+" ");
Question by:Raftor
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Author Comment

ID: 10785445
What im trying to do is to change a password in a table where the first name of the person is 'myName'.
LVL 19

Expert Comment

ID: 10785500
int num = stmt.executeUpdate("UPDATE members SET password = '"+checkPassword+"' WHERE fName LIKE "+update+" ");

This will work...
You do not have quotes up there in the pasword value...

I always prefer using prepared statments whenever it comes to update and inserts... its much more neat and predictable...

Author Comment

ID: 10785559
it is still giving me an error it is saying

 java.sql.SQLException: Column not found, message from server: "Unknown column 'Gabriel' in 'where clause'"

'Gabriel' is the 'update' string.
It works through DOS so it must be something in the format of the command.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 19

Accepted Solution

Kuldeepchaturvedi earned 200 total points
ID: 10785591
same thing in the like area as well...:-)

int num = stmt.executeUpdate("UPDATE members SET password = '"+checkPassword+"' WHERE fName LIKE '"+update+"' ");

Now you are good to go...

Author Comment

ID: 10785619
Ahh brilliant that was it.
What were you were sayin earlier about 'prepared statements' being more neat and predictable.  I think i could do with a bit of that!
LVL 19

Expert Comment

ID: 10785674
String query= "UPDATE members SET password = ?  WHERE fName LIKE ?";
 PreparedStatement ps = con.prepareStatement(query);
int num=ps.executeUpdate();

This way you don't have to worry abt quotes and all other stuff...

Author Comment

ID: 10785689
Thats great thanks.

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
What we learned in Webroot's webinar on multi-vector protection.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question