{"id":2652,"date":"2022-08-30T15:26:39","date_gmt":"2022-08-30T15:26:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/04\/block-http-post-request-if-a-record-already-exists-in-the-database-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:39","modified_gmt":"2022-08-30T15:26:39","slug":"block-http-post-request-if-a-record-already-exists-in-the-database-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/block-http-post-request-if-a-record-already-exists-in-the-database-collection-of-common-programming-errors\/","title":{"rendered":"Block HTTP POST Request if a record already exists in the database-Collection of common programming errors"},"content":{"rendered":"<p>I am developing a Java Rest web service to store user data in a MYSQL database.<\/p>\n<p>When I test try POST with curl, I get<\/p>\n<blockquote>\n<p>204 &#8211; No Content<\/p>\n<\/blockquote>\n<p>on the client side and<\/p>\n<p><code>com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'vinayUserName' for key 'name_UNIQUE'<\/code><\/p>\n<p>on the server side.<\/p>\n<p>How can I program web service to handle 409 conflict for unique data in database and communicate the message to the client?<\/p>\n<p>I am using Jersey to develop Web service and Jquery ajax on the client side to POST the data. Any help is highly appreciated.<\/p>\n<p>Thanks<\/p>\n<ol>\n<li>\n<p>You should handle SQLException ,Runtime Exception and Exception, then update webservice response with Corresponding Error Message as the parameter(Status &#8211; &#8216;Sucess\/Failure&#8217;, ErrorMessage &#8211; &#8216;Reason for Failure&#8217;).<\/p>\n<p>In the jquery extract the value from the parameters and display it to user.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-04 13:23:11. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am developing a Java Rest web service to store user data in a MYSQL database. When I test try POST with curl, I get 204 &#8211; No Content on the client side and com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry &#8216;vinayUserName&#8217; for key &#8216;name_UNIQUE&#8217; on the server side. How can I program web service to handle 409 conflict [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2652","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2652"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2652\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}