Solved

sql Update format in jsp

Posted on 2004-04-08
7
357 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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