I have an index.jsp
page from where I am inserting name and id into oracle table. I am able to insert successfully, but when user enters same employee id again index.jsp
page redirects to tomcat error page says
HTTP Status 500 javax.servlet.ServletException: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint
I want to display an error note within index.jsp
when user enters id which is already present in database.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><center>
<H1>Inserting record into a Database</H1>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.sql.DriverManager.*" %>
<%
int flag=0;
PreparedStatement ps=null;
Connection con= null;
ResultSet rs= null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("hostname","user","admin");
Statement st=con.createStatement();
String id = request.getParameter("id");
String name= request.getParameter("name");
ResultSet resultset =
rs=st.executeQuery("INSERT INTO employee (employeeid,employeename)VALUES ('"+id+"','"+name+"");
out.println("Data is successfully inserted!");
%>
</center>
</body>
</html>