Solved

sql Update format in jsp

Posted on 2004-04-08
7
352 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Pie chart in Jsp 20 215
method inner class 6 82
struts exact match support 3 56
servlet example 17 32
This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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