i ill created the program of create, insert, update, delete, exit using in jsp and mysql only. i got the solutions for insert, delete, exit, and create but, update section only i got error., in my DB name is employee and table name is employees, the fields are in the order like 1. employee name, 2. employee_id, 3. nationality,. In update part i'm using the Employee_id is displayed in default, it's also displayed but i got error in 3 field of Nationality. I send my code if you any clear my error,. thanks in advance. the coding 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>
<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(2, 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>