0

hey buddy's, i'm creating the program of employee details and i will inserted the fields are ADD,UPDATE,DELETE,EXIT,. I hope the all thing to find the exact solutions but, particular one thing only, that was UPDATE and these are the following some tips and code:
1.the input is not going store in database and,
2.the file is not updated. advance congrats for finding the solutions...

<html>
<head>
<title>
UPDATING DETAILS ABOUT EMPLOYEE
</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h3>ENTER THE EMPLOYEE DETAILS</h3><br>

<form action="editEmployee.jsp" name="UpdateForm" method="post">
<table cellspacing="1" cellpadding="1" border="1" WIDTH=90%>
<tr>
<td align="center">YOUR EMPLOYEE ID:</td><td align="center"><B><%= request.getParameter("emp_id")%></B></td>
</tr>
<tr>
<td align="center">EMPLOYEE NAME:</td>
<td align="center"><input type="text" name="EmployeeName"></td>
</tr>
<tr>
<td align="center"> EMPLOYEE NATIONLITY:</td>
<td align="center"><input type="text" name="Nationality"></td>
</tr>
</table><br><br>

<input type="submit" value="UPDATE" name="method" class="button" >
<input type="reset" value="CLEAR">
<input type="button" name="method" value="BACK TO LIST" class="button" onclick="location.href='Employeelist.jsp'"/>
</form>


<%@ page import="java.sql.*" %>
<%@ page import="java.sql.DriverManager.*" %>
<%@ page import="java.sql.Statement.*" %>
<%@ page import="java.io.*" %>

<%
String EmployeeName=request.getParameter("EmployeeName");
int Employee_id=Integer.parseInt(request.getParameter("emp_id"));
String Nationality=request.getParameter("Nationality");

    PreparedStatement ps;
    Connection con=null;

String driverName="com.mysql.jdbc.Driver";
String connectionUrl="jdbc:mysql://localhost:3306/";
String user="root";
String password="sarakrish";
String dbName="employee";

try{
    Class.forName(driverName);
    con=DriverManager.getConnection(connectionUrl+dbName,user,password);
    ps=con.prepareStatement("update employees set EmployeeName=?, Nationlity=? where Employee_id=?");
    ps.setString(1, EmployeeName);
    ps.setInt(2, Employee_id);
    ps.setString(3, Nationality);
    ps.executeUpdate();
    }
catch(ClassNotFoundException e)
    {
    out.print("ClassNotFoundException:"+e.getMessage());
    e.printStackTrace();
    }
%>

</body>
</html>          

Edited by rgkrish183: extra thingss

4
Contributors
21
Replies
68
Views
3 Years
Discussion Span
Last Post by rgkrish183
Featured Replies
  • 1

    > ps.setInt(2, Employee_id); > ps.setString(3, Nationality); Wrong order again. I suggest you add: catch(Exception e) { out.print(e.getMessage()); e.printStackTrace(); } to get more information. Read More

  • 1

    you would 've done well to first learn the basics of persistence (either jdbc, hibernate, jpa, ... ) before trying to do an entire application. just the simple insert - edit - delete statements on their own. I would also have suggested to learn to use servlets before trying to … Read More

0

They're not in the right order:

ps=con.prepareStatement("update employees set EmployeeName=?, Nationality=? where Employee_id=?");
ps.setString(1, EmployeeName);
ps.setString(2, Nationality);
ps.setInt(3, Employee_id);
0

no buddy, nothing can be changed for the o/p.
i will do the mysql table like as EmployeeName,Employee_id,Nationality
this order in my database.

0

I meant the order of the code snippet. Check my lines with yours, see the difference. The parameters need to be lined up in the same order as in the query.

0

i ill change that order but its containing same error only occured. the line was,
An exception occurred processing JSP page /WebContent/EDList/WebContent/editEmployee.jsp at line 57

        ps.setString(2, Nationality);
56:     ps.setInt(3, Employee_id);
57:     ps.executeUpdate();
58:     }
59: catch(ClassNotFoundException e)
60:     {

this the error line buddy...

0

sorry, Nationality only buddy,

An exception occurred processing JSP page /WebContent/EDList/WebContent/editEmployee.jsp at line 38

now the error was:

35: 
36: <%
37: String EmployeeName=request.getParameter("EmployeeName");
38: int Employee_id=Integer.parseInt(request.getParameter("Employee_id"));
39: String Nationality=request.getParameter("Nationality");
40: 
41:     PreparedStatement ps;
0

this is the code buddy:

<%
String EmployeeName=request.getParameter("EmployeeName");
int Employee_id=Integer.parseInt(request.getParameter("Employee_id"));
String Nationality=request.getParameter("Nationality");

    PreparedStatement ps;
    Connection con=null;

    String driverName="com.mysql.jdbc.Driver";
    String connectionUrl="jdbc:mysql://localhost:3306/";
    String user="root";
    String password="sarakrish";
    String dbName="employee";
try{
    Class.forName(driverName);
    con=DriverManager.getConnection(connectionUrl+dbName,user,password);
    ps=con.prepareStatement("update employees set EmployeeName=?, Nationality=? where Employee_id=?");
    ps.setString(1, EmployeeName);
    ps.setInt(2, Employee_id);
    ps.setString(3, Nationality);

    ps.executeUpdate();
    }
catch(ClassNotFoundException e)
    {
    out.print("ClassNotFoundException:"+e.getMessage());
    e.printStackTrace();
    }
%>
1

ps.setInt(2, Employee_id);
ps.setString(3, Nationality);

Wrong order again.

I suggest you add:

catch(Exception e)
{
    out.print(e.getMessage());
    e.printStackTrace();
}

to get more information.

Votes + Comments
patience is a virtue indeed.
0

buddy now im getting error line of:40

37: 
38: <%
39: String EmployeeName=request.getParameter("EmployeeName");
40: int Employee_id=Integer.parseInt(request.getParameter("Employee_id"));
41: String Nationality=request.getParameter("Nationality");
42: 
43:     PreparedStatement ps;
0

It MIGHT help to know WHAT error you are getting (you will probably have to look at the logs). But what will REALLY help is to STOP WITH THE SCRIPTLETS. Program PROPERLY.

0

1.buddy i will do some changes then i got that page but its not update the values. i do the updations is default setting in emp_id, that emp_id was constant for that particular updations only.

2.but, now i got this error:Parameter index out of range (3 > number of parameters, which is 2).

3.as the code following as:

<%@ page import="java.sql.*" %>
<%@ page import="java.sql.DriverManager.*" %>
<%@ page import="java.sql.Statement.*" %>
<%@ page import="java.io.*" %>

<html>
<head>
<title>
UPDATING DETAILS ABOUT EMPLOYEE
</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h3>ENTER THE EMPLOYEE DETAILS</h3><br>

<form action="editEmployee.jsp" name="UpdateForm" method="post">
<table cellspacing="1" cellpadding="1" border="1" WIDTH=90%>
<tr>
<td align="center">YOUR EMPLOYEE ID:</td><td align="center"><B><%= request.getParameter("emp_id")%></B></td>
</tr>
<tr>
<tr>
<td align="center">EMPLOYEE NAME:</td>
<td align="center"><input type="text" name="EmployeeName"></td>
</tr>
<tr>
<td align="center"> EMPLOYEE NATIONLITY:</td>
<td align="center"><input type="text" name="Nationality"></td>
</tr>

<%
String EmployeeName=request.getParameter("EmployeeName");

String Nationality=request.getParameter("Nationality");

    PreparedStatement ps;
    Connection con=null;

    String driverName="com.mysql.jdbc.Driver";
    String connectionUrl="jdbc:mysql://localhost:3306/";
    String user="root";
    String password="sarakrish";
    String dbName="employee";
try{
    Class.forName(driverName);
    con=DriverManager.getConnection(connectionUrl+dbName,user,password);
    ps=con.prepareStatement("update employees set EmployeeName=?,Nationality=?");
    ps.setString(1, EmployeeName);
    ps.setString(3, Nationality);
    ps.executeUpdate();
    }
catch(Exception e)
    {
    out.print(e.getMessage());
    e.printStackTrace();
    }
%>


</table><br><br>
<input type="submit" value="UPDATE" name="method" class="button" >
<input type="reset" value="CLEAR">
<input type="button" name="method" value="BACK TO LIST" class="button" onclick="location.href='Employeelist.jsp'"/>
</form>

</body>
</html>          

i ill mark that code in this symbols...

Edited by rgkrish183: alter that webpage

Attachments
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 12">
<meta name=Originator content="Microsoft Word 12">
<link rel=File-List href="j_files/filelist.xml">
<link rel=Edit-Time-Data href="j_files/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>UPDATING DETAILS ABOUT EMPLOYEE</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>jtechusers</o:Author>
  <o:Template>Normal</o:Template>
  <o:LastAuthor>jtechusers</o:LastAuthor>
  <o:Revision>2</o:Revision>
  <o:TotalTime>1</o:TotalTime>
  <o:Created>2014-01-27T14:26:00Z</o:Created>
  <o:LastSaved>2014-01-27T14:26:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>25</o:Words>
  <o:Characters>317</o:Characters>
  <o:Lines>2</o:Lines>
  <o:Paragraphs>1</o:Paragraphs>
  <o:CharactersWithSpaces>341</o:CharactersWithSpaces>
  <o:Version>12.00</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<link rel=themeData href="j_files/themedata.thmx">
<link rel=colorSchemeMapping href="j_files/colorschememapping.xml">
<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:Zoom>105</w:Zoom>
  <w:TrackMoves/>
  <w:TrackFormatting/>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:DoNotPromoteQF/>
  <w:LidThemeOther>EN-US</w:LidThemeOther>
  <w:LidThemeAsian>X-NONE</w:LidThemeAsian>
  <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:SplitPgBreakAndParaMark/>
   <w:DontVertAlignCellWithSp/>
   <w:DontBreakConstrainedForcedTables/>
   <w:DontVertAlignInTxbx/>
   <w:Word11KerningPairs/>
   <w:CachedColBalance/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
  <m:mathPr>
   <m:mathFont m:val="Cambria Math"/>
   <m:brkBin m:val="before"/>
   <m:brkBinSub m:val="--"/>
   <m:smallFrac m:val="off"/>
   <m:dispDef/>
   <m:lMargin m:val="0"/>
   <m:rMargin m:val="0"/>
   <m:defJc m:val="centerGroup"/>
   <m:wrapIndent m:val="1440"/>
   <m:intLim m:val="subSup"/>
   <m:naryLim m:val="undOvr"/>
  </m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
  DefSemiHidden="true" DefQFormat="false" DefPriority="99"
  LatentStyleCount="267">
  <w:LsdException Locked="false" Priority="0" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="heading 3"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 1"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 2"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 3"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 4"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 5"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 6"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 7"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 8"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 9"/>
  <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
  <w:LsdException Locked="false" Priority="10" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Title"/>
  <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
  <w:LsdException Locked="false" Priority="11" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
  <w:LsdException Locked="false" Priority="22" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
  <w:LsdException Locked="false" Priority="20" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
  <w:LsdException Locked="false" Priority="59" SemiHidden="false"
   UnhideWhenUsed="false" Name="Table Grid"/>
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
  <w:LsdException Locked="false" Priority="1" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 1"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
  <w:LsdException Locked="false" Priority="34" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
  <w:LsdException Locked="false" Priority="29" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
  <w:LsdException Locked="false" Priority="30" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 1"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 2"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWh
0

this that page

Attachments
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 12">
<meta name=Originator content="Microsoft Word 12">
<link rel=File-List href="j_files/filelist.xml">
<link rel=Edit-Time-Data href="j_files/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>UPDATING DETAILS ABOUT EMPLOYEE</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>jtechusers</o:Author>
  <o:Template>Normal</o:Template>
  <o:LastAuthor>jtechusers</o:LastAuthor>
  <o:Revision>2</o:Revision>
  <o:TotalTime>1</o:TotalTime>
  <o:Created>2014-01-27T14:26:00Z</o:Created>
  <o:LastSaved>2014-01-27T14:26:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>25</o:Words>
  <o:Characters>317</o:Characters>
  <o:Lines>2</o:Lines>
  <o:Paragraphs>1</o:Paragraphs>
  <o:CharactersWithSpaces>341</o:CharactersWithSpaces>
  <o:Version>12.00</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<link rel=themeData href="j_files/themedata.thmx">
<link rel=colorSchemeMapping href="j_files/colorschememapping.xml">
<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:Zoom>105</w:Zoom>
  <w:TrackMoves/>
  <w:TrackFormatting/>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:DoNotPromoteQF/>
  <w:LidThemeOther>EN-US</w:LidThemeOther>
  <w:LidThemeAsian>X-NONE</w:LidThemeAsian>
  <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:SplitPgBreakAndParaMark/>
   <w:DontVertAlignCellWithSp/>
   <w:DontBreakConstrainedForcedTables/>
   <w:DontVertAlignInTxbx/>
   <w:Word11KerningPairs/>
   <w:CachedColBalance/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
  <m:mathPr>
   <m:mathFont m:val="Cambria Math"/>
   <m:brkBin m:val="before"/>
   <m:brkBinSub m:val="--"/>
   <m:smallFrac m:val="off"/>
   <m:dispDef/>
   <m:lMargin m:val="0"/>
   <m:rMargin m:val="0"/>
   <m:defJc m:val="centerGroup"/>
   <m:wrapIndent m:val="1440"/>
   <m:intLim m:val="subSup"/>
   <m:naryLim m:val="undOvr"/>
  </m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
  DefSemiHidden="true" DefQFormat="false" DefPriority="99"
  LatentStyleCount="267">
  <w:LsdException Locked="false" Priority="0" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="heading 3"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 1"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 2"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 3"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 4"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 5"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 6"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 7"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 8"/>
  <w:LsdException Locked="false" Priority="39" Name="toc 9"/>
  <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
  <w:LsdException Locked="false" Priority="10" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Title"/>
  <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
  <w:LsdException Locked="false" Priority="11" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
  <w:LsdException Locked="false" Priority="22" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
  <w:LsdException Locked="false" Priority="20" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
  <w:LsdException Locked="false" Priority="59" SemiHidden="false"
   UnhideWhenUsed="false" Name="Table Grid"/>
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
  <w:LsdException Locked="false" Priority="1" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 1"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
  <w:LsdException Locked="false" Priority="34" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
  <w:LsdException Locked="false" Priority="29" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
  <w:LsdException Locked="false" Priority="30" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 1"/>
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 2"/>
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWh
0
ps=con.prepareStatement("update employees set EmployeeName=?,Nationality=?");
ps.setString(1, EmployeeName);
ps.setString(3, Nationality);

Uhm, where did the "where clause" portion of the statement go? And how many question marks do you count in this statement? And is the index you used larger than this?

0

yeah i know that, but i ill doing in the database 1.EmployeeName 2.Employee_id 3.Nationality in this order.

i ill change this order, i got this error:>

Unknown column 'Nationality' in 'field list'

con=DriverManager.getConnection(connectionUrl+dbName,user,password);
        ps=con.prepareStatement("update employees set EmployeeName=?,Nationality=?");
        ps.setString(1, EmployeeName);
        ps.setString(2, Nationality);
        ps.executeUpdate();
        }

Edited by rgkrish183: nothing

0

Then LOOK at your DB. Is the column REALLY named like that, EXACTLY like that.

And, it doesn't matter in what order the columns were created and/or exist in the db, these index numbers are PARAMETER indexes and are ONLY concerned with the number and position of the parameters (i.e. question marks) in the QUERY.

1

you would 've done well to first learn the basics of persistence (either jdbc, hibernate, jpa, ... ) before trying to do an entire application.
just the simple insert - edit - delete statements on their own.

I would also have suggested to learn to use servlets before trying to use a database in your application.
keep writing scriplets in your jsp files, and it'll become a lot harder than it needs to be to debug/maintain.

0

keep writing scriplets in your jsp files, and it'll become a lot harder than it needs to be to debug/maintain.

I have told this guy not to do this multiple times in multiple threads.

0

k buddy thanks for all comments and replys, i ill do some changes and finally i got the o/p. little much know in scriplets so, i must learn the scriplets. And the code is following as:

<%@ page import="java.sql.*" %>


    <%@ page import="java.sql.DriverManager.*" %>
    <%@ page import="java.sql.Statement.*" %>
    <%@ page import="java.io.*" %>

    <%

        PreparedStatement ps;
        Connection con=null;

        ResultSet rs=null;
        Statement st=null;


        String driverName="com.mysql.jdbc.Driver";
        String connectionUrl="jdbc:mysql://localhost:3306/";
        String user="root";
        String password="sarakrish";
        String dbName="employee";

        String emp_id = "";
        String emp_name = "";
        String nationality = "";
        try{
            Class.forName(driverName);
            con=DriverManager.getConnection(connectionUrl+dbName,user,password);

            if(request.getParameter("edit")!=null && request.getParameter("edit").toString().equals("yes")){
                String EmployeeId = request.getParameter("emp_id");
                String EmployeeName=request.getParameter("EmployeeName");
                String Nationality=request.getParameter("Nationality");

                ps=con.prepareStatement("update employees set EmployeeName=?,Nationlity=? where Employee_id=?");
                ps.setString(1, EmployeeName);
                ps.setString(2, Nationality);
                ps.setString(3, EmployeeId);
                ps.executeUpdate();
                ps.close();
            }
            st = con.createStatement();
            String sql="SELECT * FROM employees where employee_id='"+request.getParameter("emp_id")+"'";
            rs=st.executeQuery(sql);
            while (rs.next()) {
                emp_id = rs.getString(2);
                emp_name = rs.getString(1);
                nationality = rs.getString(3);
                break;
            }       
            rs.close();
            st.close();

            con.close();        
        }catch(Exception e){
            out.print(e.getMessage());
            e.printStackTrace();
        }

    %>

    <html>
    <head>
    <title>
    UPDATING DETAILS ABOUT EMPLOYEE
    </title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <h3>ENTER THE EMPLOYEE DETAILS</h3><br>
    <%=request.getParameter("edit")%>
    <form action="editEmployee.jsp" name="UpdateForm" method="post">
    <input type="hidden" name="edit" id="edit" value="yes">
    <input type="hidden" name="emp_id" id="emp_id" value="<%=emp_id %>">
    <table cellspacing="1" cellpadding="1" border="1" WIDTH=90%>
    <tr>
    <td align="center">YOUR EMPLOYEE ID:</td><td align="center"><B><%= request.getParameter("emp_id")%></B></td>
    </tr>
    <tr>
    <td align="center">EMPLOYEE NAME:</td>
    <td align="center"><input type="text" name="EmployeeName" value="<%=emp_name %>"></td>
    </tr>
    <tr>
    <td align="center"> EMPLOYEE NATIONLITY:</td>
    <td align="center"><input type="text" name="Nationality" value="<%=nationality %>"></td>
    </tr>



    </table><br><br>
    <input type="submit" value="UPDATE" name="method" class="button" >
    <input type="reset" value="CLEAR">
    <input type="button" name="method" value="BACK TO LIST" class="button" onclick="location.href='Employeelist.jsp'"/>
    </form>

    </body>
    </html>          
0

BTW THIS

String sql="SELECT * FROM employees where employee_id='"+request.getParameter("emp_id")+"'";

Is just BEGGING for SQL syntax errors and/or SQL injection attacks.

0

hey stultuske, hmm yeah buddy, today only ill start, thanks for the comment.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.