473,385 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to update the DB values using the getParameter()

hai,

I want to update the database table values using the getParameter().

int rs=statement.executeUpdate("update address set name='xxxx' where name=("+request.getParameter("oldname")+")");

This code is giving this error .

javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

please can enybody help me.

thanks in advance.
Jul 19 '07 #1
5 2026
hai,

I want to update the database table values using the getParameter().

int rs=statement.executeUpdate("update address set name='xxxx' where name=("+request.getParameter("oldname")+")");

This code is giving this error .

javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

please can enybody help me.

thanks in advance.


hi,
I thought that error occurs at name=("+request.getParameter("oldname")+")"),
once try with this
name='"+request.getParameter("oldname")+"'
request.getParameter("oldname") should be within the single quotes.
Jul 20 '07 #2
nickyeng
254 100+
hai,

I want to update the database table values using the getParameter().

int rs=statement.executeUpdate("update address set name='xxxx' where name=("+request.getParameter("oldname")+")");

This code is giving this error .

javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

please can enybody help me.

thanks in advance.
why not use a string to get the parameter and set for the field in table?
Expand|Select|Wrap|Line Numbers
  1. // use string to get parameter from request
  2. String str = request.getParameter("oldname");
  3.  
  4. // update the database
  5. int rs=statement.executeUpdate("update address set name='xxxx' where name="+str);
  6.  
i hope it helps....
Jul 20 '07 #3
sumittyagi
202 Expert 100+
why not use a string to get the parameter and set for the field in table?
Expand|Select|Wrap|Line Numbers
  1. // use string to get parameter from request
  2. String str = request.getParameter("oldname");
  3.  
  4. // update the database
  5. int rs=statement.executeUpdate("update address set name='xxxx' where name="+str);
  6.  
i hope it helps....
don't forget quotes
int rs=statement.executeUpdate("update address set name='xxxx' where name='"+str+"'");

and a null check. (if parameter doesn't exist).

Expand|Select|Wrap|Line Numbers
  1. String oldName = request.getParameter("oldname");
  2. StringBuffer sql = null;
  3. if(oldName !=null) //also add any other constraint you want to check.
  4. {
  5.     sql = new StringBuffer("update address set ");
  6.     sql.append(" name='xxx' ");
  7.     sql.append(" where name='");
  8.     sql.append(oldName);
  9.     sql.append("'");
  10. }
  11. int noOfUpdatedRecords = 0;
  12. if(sql!=null)
  13. {
  14.     noOfUpdatedRecords = statement.executeUpdate(sql.toString());
  15. }
  16.  
Or its better to use PreparedStatement.
Jul 20 '07 #4
nickyeng
254 100+
don't forget quotes
int rs=statement.executeUpdate("update address set name='xxxx' where name='"+str+"'");

and a null check. (if parameter doesn't exist).

Expand|Select|Wrap|Line Numbers
  1. String oldName = request.getParameter("oldname");
  2. StringBuffer sql = null;
  3. if(oldName !=null) //also add any other constraint you want to check.
  4. {
  5.     sql = new StringBuffer("update address set ");
  6.     sql.append(" name='xxx' ");
  7.     sql.append(" where name='");
  8.     sql.append(oldName);
  9.     sql.append("'");
  10. }
  11. int noOfUpdatedRecords = 0;
  12. if(sql!=null)
  13. {
  14.     noOfUpdatedRecords = statement.executeUpdate(sql.toString());
  15. }
  16.  
Or its better to use PreparedStatement.
thanks for the tips, but then i dont use it in my code with the quotes.
i used Statement for it...
why?
Jul 23 '07 #5
sumittyagi
202 Expert 100+
thanks for the tips, but then i dont use it in my code with the quotes.
i used Statement for it...
why?
I am not getting what exactly you want to ask. Please elaborate your confusion.
Jul 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
1
by: Cat | last post by:
I'm trying to create a online update form to a SQL table. I've never done this function before, and I'm not quite sure I have the coding correct. Below is the coding for the Update statement. ...
4
by: prasath03 | last post by:
Dear All, Can anybody help me about my coding, i'm inserting the image file to database using jsp. When i execute the code, the following error is occurred: java.sql.SQLException: Insert...
5
by: Nirmala123 | last post by:
hi... I want to sort the table using combobox values. I give the code here. address.html: <html> <head> <title>Add a new entry</title> </head>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.