updateRecords.jsp
<%@ page language = "java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import = "java.sql.*"%>
<%@page import="java.util.*"%>
<%! boolean success = false; %>
<%
int id = Integer.parseInt(request.getParameter("tid"));
int eid = Integer.parseInt(request.getParameter("employeeID"));
String empName = request.getParameter("employeeName");
String sql= "UPDATE EMP_DETAIL SET emp_id = '"+eid+"', emp_name = '"+empName+"' WHERE id = '" +id+ "'";
Connection con = null;
PreparedStatement psmt = null;
String url = "jdbc:mysql://localhost:3306/test_db";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url,userName,password);
psmt = con.prepareStatement(sql);
//psmt.setInt(2, eid);
//psmt.setString(3, empName);
int nRows = psmt.executeUpdate();
if(nRows == 0){
success = false;
}
else{
success = true;
}
psmt.close(); con.close();
%>
<%
if(success = true){
%>
Record updated |
View Records |
<%
}
else {
%>
Error - can not be updated |
View Records |
<%
}
%>
0 comments:
Post a Comment