Solved

sql Update format in jsp

Posted on 2004-04-08
7
361 Views
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+" ");
                              
0
Comment
Question by:Raftor
[X]
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
7 Comments
 

Author Comment

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

Expert Comment

by:Kuldeepchaturvedi
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...
0
 

Author Comment

by:Raftor
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.
0
Industry Leaders: 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

by:
Kuldeepchaturvedi earned 50 total points
ID: 10785591
Ooops
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...
0
 

Author Comment

by:Raftor
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!
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10785674
String query= "UPDATE members SET password = ?  WHERE fName LIKE ?";
 PreparedStatement ps = con.prepareStatement(query);
ps.setString(1,checkPassword);
ps.setString(2,update);
int num=ps.executeUpdate();

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

Author Comment

by:Raftor
ID: 10785689
Thats great thanks.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
String format issue 13 93
gZip compression filter 2 190
doubleChar java challenge 7 130
jdbc error in jsp application 20 91
This article describes a serious pitfall that can happen when deleting shapes using VBA.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

751 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