X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4A83832A502 for ; Fri, 15 Oct 2004 00:00:26 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93824-01 for ; Thu, 14 Oct 2004 23:00:20 +0000 (GMT) Received: from main.gmane.org (main.gmane.org [80.91.229.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6749A329F4B for ; Fri, 15 Oct 2004 00:00:21 +0100 (BST) Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1CIEa4-0001IZ-00 for ; Fri, 15 Oct 2004 01:00:20 +0200 Received: from c-24-0-215-208.client.comcast.net ([24.0.215.208]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Oct 2004 01:00:20 +0200 Received: from i.pilcher by c-24-0-215-208.client.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Oct 2004 01:00:20 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Ian Pilcher Subject: Mining SQLException for info Date: Thu, 14 Oct 2004 18:00:11 -0500 Lines: 57 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: c-24-0-215-208.client.comcast.net User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040922 X-Accept-Language: en-us, en X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/151 X-Sequence-Number: 11256 I am using Tomcat and PostgreSQL to create a browser-based "jukebox" for my music collection. Actually, it's more accurate to say that I'm using the jukebox project as a vehicle to learn Java, JDBC, servlets, JSPs, SQL, etc. Either way, at this rate I should something quite usable in about ten years. :-) I'm currently wrestling with the problem of data integrity, and what layer of the application should enforce it. I've identified three possible high-level approaches: 1) Data integrity is enforced at the application (servlet) level only. The database accepts whatever the application gives it. 2) Data integrity is enforced only at the database level. The application attempts to put whatever the user inputs into the database. 3) All data integrity checks are performed at both levels. Ignore, for a moment, the fact that no application will ever fit completely into one of these patterns. Although option #1 may look silly, especially on a RDBMS-related list, it does have one important benefit. The application can provide far better feedback to the user if it has detailed information about what the exact data integrity problem is. Nevertheless, I've ruled it out, because there's really no point in using an RDBMS (at least not Post- greSQL) if you're not going to use it's data integrity features. Option #3 is somewhat tempting. The application will be able to provide useful feedback to users about data problems, and the database won't accept problematic data. Any data integrity violation at the database level is, by definition, a bug in the application. Keeping the two sets of data integrity rules in sync, however, will inevitably prove problematic. It's also simply inelegant to do everything twice. Which brings me to option #2, the option I've chosen. Given my desire to provide good feedback, I want to squeeze as much information as possible out of any SQLException that comes back -- at least those related to integrity violations (23xxx) and exceptions in TRIGGER functions. The only technique I can come up with is to name all of my constraints and, based on the code returned by getSQLState parse the String returned by getMessage. Uugh! Is there a better way that I haven't thought of? If there isn't, are there anything I can do to make the message parsing more robust -- across PostgreSQL version changes and different locales, for example? Thanks! -- ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================