Problem with updating a record in database | Newbie | | Join Date: Jun 2007
Posts: 21
| | |
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());
}
}
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: Problem with updating a record in database Quote:
Originally Posted by veerapureddy 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?
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Problem with updating a record in database
I think u didn't Connection.commit() after executeUpdate().
Do the commit then the reflection ll happen.
Best of luck.
Kind regards,
Dmjpro.
| | Newbie | | Join Date: Jun 2007
Posts: 21
| | | re: Problem with updating a record in database Quote:
Originally Posted by r035198x 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?
| | Newbie | | Join Date: Jun 2007
Posts: 21
| | | re: Problem with updating a record in database Quote:
Originally Posted by dmjpro 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
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Problem with updating a record in database Quote:
Originally Posted by veerapureddy 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 ..... -
Connection l_con = null;
-
//Code for connection making
-
l_con.commit(); //The changes u did in this session reflects to the database.
-
For details see the SUN API Documentation for Connection interface.
Have a good day.
Kind regards,
Dmjpro.
| | Newbie | | Join Date: Jun 2007
Posts: 21
| | | re: Problem with updating a record in database Quote:
Originally Posted by dmjpro 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 ..... -
Connection l_con = null;
-
//Code for connection making
-
l_con.commit(); //The changes u did in this session reflects to the database.
-
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®ards
veerapureddy
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: Problem with updating a record in database Quote:
Originally Posted by veerapureddy 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®ards
veerapureddy U welcome.
So u came to know how to use commit and why it is?
Right?
Have a good day.
Kind regards,
DMjpro.
| | Newbie | | Join Date: Jun 2007
Posts: 21
| | | re: Problem with updating a record in database Quote:
Originally Posted by dmjpro 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
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,366 network members.
|