Note that there are some explanatory texts on larger screens.

plurals
  1. POError:Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException
    primarykey
    data
    text
    <p>I am getting this error because of primary key constraint violation my question is how can i catch all these exceptions .</p> <pre><code>HTTP ERROR 500 Problem accessing /persist_role_servlet. Reason: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Duplicate entry 'sd' for key 'PRIMARY' Error Code: 1062 Call: INSERT INTO ROLE (ROLE_ID, ROLE_DESC, ROLE_NAME) VALUES (?, ?, ?) bind =&gt; [3 parameters bound] Query: InsertObjectQuery(com.example.rolessample.role@3f1179) Caused by: javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Duplicate entry 'sd' for key 'PRIMARY' Error Code: 1062 Call: INSERT INTO ROLE (ROLE_ID, ROLE_DESC, ROLE_NAME) VALUES (?, ?, ?) bind =&gt; [3 parameters bound] </code></pre> <p><strong>This my servlets code:</strong></p> <pre><code>package com.example.rolessample; import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class persist_role_servlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter out = resp.getWriter(); String role_id = req.getParameter("role_id"); String role_name = req.getParameter("role_name"); String role_desc = req.getParameter("role_desc"); String comp_id = ""; String parent_comp = ""; String permission = ""; role r = new role(); r.setRole_id(role_id); r.setRole_name(role_name); r.setRole_desc(role_desc); //Persisting the role bean . EntityManager em = EMF.get().createEntityManager(); EntityTransaction tx = em.getTransaction(); tx.begin(); em.persist(r); tx.commit(); String[] checkboxNamesList = req.getParameterValues("component"); for (int i = 0; i &lt; checkboxNamesList.length; i++) { String[] myCheckBoxValue = req .getParameterValues(checkboxNamesList[i]); //If null, it means checkbox is not in request, so unchecked if (myCheckBoxValue == null) { component comp = new component(); //Logic for finding component's name,component parent and their permissions. String S1 = checkboxNamesList[i]; int lastUnderscore = S1.lastIndexOf("_"); permission = S1.substring(lastUnderscore + 1); comp_id = S1.substring(0, lastUnderscore); lastUnderscore = comp_id.lastIndexOf("_"); parent_comp = comp_id.substring(0, lastUnderscore); comp.setComp_id(comp_id); comp.setParent_comp(parent_comp); comp.setRole_id(role_id); comp.setPermission(permission); //Persisting component bean . tx.begin(); em.persist(comp); tx.commit(); } // if is there, it means checkbox checked else { out.println(checkboxNamesList[i] + "=checked"); } } // resp.setHeader("Refresh", "0; url=/guestbook.jsp"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload