473,400 Members | 2,145 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,400 software developers and data experts.

Problem with updating a record in database

Hai everybody,

I am facing problem with updating a record .actullay im getting some data from database(Access) and populating it on a html form.im trying to edit some texts and update, its not reflecting in database. here is the code.
(the request parameters from html form, there is no mismatch between variable names)
************************************************** ******************************************private void updateEmployee(HttpServletRequest request, HttpServletResponse response) throws IOException{
PrintWriter out = response.getWriter();
String firstname=request.getParameter("firstname");
String lastname=request.getParameter("lastname");
String empid=request.getParameter("empid");
String extnnum = request.getParameter("extnno");
String lotusmailid=request.getParameter("lotusmailid");
String personalmailid=request.getParameter("personalmaili d");
String pplmanager=request.getParameter("pplmanager");
String projectmanager=request.getParameter("projectmanage r");
String hrid=request.getParameter("hrid");
String unixlogin=request.getParameter("unixlogin");
String attuid=request.getParameter("attuid");
String portnum=request.getParameter("portno");
String address=request.getParameter("address");
String city=request.getParameter("city");
String state=request.getParameter("state");
String pincode=request.getParameter("pincode");
String mobnum=request.getParameter("mobno");
String homenum=request.getParameter("hometelno");
String project=request.getParameter("project");
String teamleader=request.getParameter("teamleader");
out.println("EMP ID IS:"+empid);


try
{


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:giom");
System.out.println("GOT CONNECTION FOR EMPLOYEE UPDATE HANDLER ");
Statement s = con.createStatement();

System.out.println("GOT CONNECTION yaar");
String sql = "UPDATE EMPLOYEE SET FNAME='"+ firstname +"', LNAME='"+ lastname +"', OFF_EMAIL='"+ lotusmailid +"',PRSNL_EMAIL='"+ personalmailid +"',PPL_MANAGER='"+ pplmanager +"',PROJECT_MANAGER='"+ projectmanager +"',EXTN='"+ extnnum +"',PROJECT='"+ project+"',TEAM_LEADER='"+ teamleader +"',HRID='"+ hrid +"',ATT_UID='"+ attuid +"',UNIX_LOGIN='"+ unixlogin+"',PORT_NO='"+ portnum+"',MOBILE_NO='"+ mobnum +"',HOME_NO='"+ homenum +"',CONT_ADDR='"+ address +"',CITY='"+ city +"',STATE='"+ state +"',PINCODE='"+ pincode +"' WHERE EMP_ID='"+ empid +"'" ;


int i = s.executeUpdate(sql);
System.out.println("i value is :"+i);
if (i!= 0)
{
String message = "Successfully deleted"+i+" users.";
System.out.println(message);
out.println(message);
}
}
catch (ClassNotFoundException e) {
System.out.println(e.toString());
}
catch (SQLException e) {
e.printStackTrace();
}
catch (Exception e) {
System.out.println(e.toString());
}


}
Jun 4 '07 #1
8 1562
r035198x
13,262 8TB
Hai everybody,

I am facing problem with updating a record .actullay im getting some data from database(Access) and populating it on a html form.im trying to edit some texts and update, its not reflecting in database. here is the code.
(the request parameters from html form, there is no mismatch between variable names)
************************************************** ******************************************private void updateEmployee(HttpServletRequest request, HttpServletResponse response) throws IOException{
PrintWriter out = response.getWriter();
String firstname=request.getParameter("firstname");
String lastname=request.getParameter("lastname");
String empid=request.getParameter("empid");
String extnnum = request.getParameter("extnno");
String lotusmailid=request.getParameter("lotusmailid");
String personalmailid=request.getParameter("personalmaili d");
String pplmanager=request.getParameter("pplmanager");
String projectmanager=request.getParameter("projectmanage r");
String hrid=request.getParameter("hrid");
String unixlogin=request.getParameter("unixlogin");
String attuid=request.getParameter("attuid");
String portnum=request.getParameter("portno");
String address=request.getParameter("address");
String city=request.getParameter("city");
String state=request.getParameter("state");
String pincode=request.getParameter("pincode");
String mobnum=request.getParameter("mobno");
String homenum=request.getParameter("hometelno");
String project=request.getParameter("project");
String teamleader=request.getParameter("teamleader");
out.println("EMP ID IS:"+empid);


try
{


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:giom");
System.out.println("GOT CONNECTION FOR EMPLOYEE UPDATE HANDLER ");
Statement s = con.createStatement();

System.out.println("GOT CONNECTION yaar");
String sql = "UPDATE EMPLOYEE SET FNAME='"+ firstname +"', LNAME='"+ lastname +"', OFF_EMAIL='"+ lotusmailid +"',PRSNL_EMAIL='"+ personalmailid +"',PPL_MANAGER='"+ pplmanager +"',PROJECT_MANAGER='"+ projectmanager +"',EXTN='"+ extnnum +"',PROJECT='"+ project+"',TEAM_LEADER='"+ teamleader +"',HRID='"+ hrid +"',ATT_UID='"+ attuid +"',UNIX_LOGIN='"+ unixlogin+"',PORT_NO='"+ portnum+"',MOBILE_NO='"+ mobnum +"',HOME_NO='"+ homenum +"',CONT_ADDR='"+ address +"',CITY='"+ city +"',STATE='"+ state +"',PINCODE='"+ pincode +"' WHERE EMP_ID='"+ empid +"'" ;


int i = s.executeUpdate(sql);
System.out.println("i value is :"+i);
if (i!= 0)
{
String message = "Successfully deleted"+i+" users.";
System.out.println(message);
out.println(message);
}
}
catch (ClassNotFoundException e) {
System.out.println(e.toString());
}
catch (SQLException e) {
e.printStackTrace();
}
catch (Exception e) {
System.out.println(e.toString());
}


}
It is a good idea to always close one's connections.
So what happens when you run it? Is anything printed to the console?
Jun 5 '07 #2
dmjpro
2,476 2GB
I think u didn't Connection.commit() after executeUpdate().
Do the commit then the reflection ll happen.
Best of luck.

Kind regards,
Dmjpro.
Jun 5 '07 #3
It is a good idea to always close one's connections.
So what happens when you run it? Is anything printed to the console?
hai r035198x,

Thanks for replying.

ouput on console:

GOT CONNECTION FOR EMPLOYEE UPDATE HANDLER
GOT CONNECTION YAAR
i value is:0

i dont know , where i am doing the mistake?
Jun 5 '07 #4
I think u didn't Connection.commit() after executeUpdate().
Do the commit then the reflection ll happen.
Best of luck.

Kind regards,
Dmjpro.
hai dmjpro,

Thanks for your reply to this post.

i got the connection for databse.
the output on console is:
GOT CONNECTION FOR EMPLOYEE UPDATE HANDLER
GOT CONNECTION YAAR
i values is :0
i dont have idea about commit() function.

can u tell me , where i am doing the mistake.

Thanks
veerapureddy
Jun 5 '07 #5
dmjpro
2,476 2GB
hai dmjpro,

Thanks for your reply to this post.

i got the connection for databse.
the output on console is:
GOT CONNECTION FOR EMPLOYEE UPDATE HANDLER
GOT CONNECTION YAAR
i values is :0
i dont have idea about commit() function.

can u tell me , where i am doing the mistake.

Thanks
veerapureddy
Ok.
Do u know the meaning of return value is 0?
Ok, Let's explain.
It means the number of updated rows is 0.
Check out the where clause u used in UPDATE Query.
Print the update query string into console and try to run in Oracle Client (SQL* or Toad or SQL Navigator or anything else u have).

Now let's explain what is commit.
When a database connection is opened then a database session starts.
Now a change made in a session only changes reflected in that session.
The changes is not reflected to the atabase untill u do a commit to the database.
As u r in JAVA then call the commit like this .....

Expand|Select|Wrap|Line Numbers
  1. Connection l_con = null;
  2. //Code for connection making
  3. l_con.commit(); //The changes u did in this session reflects to the database.
  4.  
For details see the SUN API Documentation for Connection interface.
Have a good day.

Kind regards,
Dmjpro.
Jun 5 '07 #6
Ok.
Do u know the meaning of return value is 0?
Ok, Let's explain.
It means the number of updated rows is 0.
Check out the where clause u used in UPDATE Query.
Print the update query string into console and try to run in Oracle Client (SQL* or Toad or SQL Navigator or anything else u have).

Now let's explain what is commit.
When a database connection is opened then a database session starts.
Now a change made in a session only changes reflected in that session.
The changes is not reflected to the atabase untill u do a commit to the database.
As u r in JAVA then call the commit like this .....

Expand|Select|Wrap|Line Numbers
  1. Connection l_con = null;
  2. //Code for connection making
  3. l_con.commit(); //The changes u did in this session reflects to the database.
  4.  
For details see the SUN API Documentation for Connection interface.
Have a good day.

Kind regards,
Dmjpro.
Hai Dmjpro,

Thanks a lot , now its working. After printing sql query on console, i am able to detect the false and i corrected it.the problem is , ididnt use trim function for empid in where clause(sql query), so its taking white spaces and not matching the data with database data.thanks for your valuable time

Thanks&regards
veerapureddy
Jun 5 '07 #7
dmjpro
2,476 2GB
Hai Dmjpro,

Thanks a lot , now its working. After printing sql query on console, i am able to detect the false and i corrected it.the problem is , ididnt use trim function for empid in where clause(sql query), so its taking white spaces and not matching the data with database data.thanks for your valuable time

Thanks&regards
veerapureddy
U welcome.
So u came to know how to use commit and why it is?
Right?
Have a good day.

Kind regards,
DMjpro.
Jun 5 '07 #8
U welcome.
So u came to know how to use commit and why it is?
Right?
Have a good day.

Kind regards,
DMjpro.

Yes DMjpro, i understand the concept of commit function.

thank you very much
Jun 6 '07 #9

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

Similar topics

4
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes,...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
4
by: Prabhat | last post by:
How do I lock a particular record that one user has opened for editing? If I use the pessimistic type, can other users view the record (but not edit it) and return a message telling that another...
9
by: zMisc | last post by:
When I try to update record, I kept getting this error: Row cannot be located for updating. Some values may have been changed since it was last read. No other users are accessing the database...
5
by: Hexman | last post by:
I've come up with an error which the solution eludes me. I get the error: >An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in HRTest.exe > >Additional...
6
by: Bernie Hunt | last post by:
I have a simple app that grabs records from a database and steps through them processing each record. I have three text fields on the form to give the user feedback on the progress. With each...
15
by: Scotty | last post by:
I like to have a good insert, update and delete code The code below sometimes workl ok sometimes doesnt work, what i am doing wrong?? Sub SaveAny() Dim command_builder As New...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.