From derby-user-return-5791-apmail-db-derby-user-archive=db.apache.org@db.apache.org Wed Dec 06 19:09:09 2006 Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 59260 invoked from network); 6 Dec 2006 19:09:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Dec 2006 19:09:07 -0000 Received: (qmail 28933 invoked by uid 500); 6 Dec 2006 19:09:14 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 28911 invoked by uid 500); 6 Dec 2006 19:09:14 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 28900 invoked by uid 99); 6 Dec 2006 19:09:14 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Dec 2006 11:09:14 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of lists@nabble.com designates 72.21.53.35 as permitted sender) Received: from [72.21.53.35] (HELO talk.nabble.com) (72.21.53.35) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Dec 2006 11:09:01 -0800 Received: from [72.21.53.38] (helo=jubjub.nabble.com) by talk.nabble.com with esmtp (Exim 4.50) id 1Gs28G-0007q2-Tb for derby-user@db.apache.org; Wed, 06 Dec 2006 11:08:40 -0800 Message-ID: <7725706.post@talk.nabble.com> Date: Wed, 6 Dec 2006 11:08:40 -0800 (PST) From: Sisilla To: derby-user@db.apache.org Subject: Re: java method called from a JSP cannot load ClientDriver In-Reply-To: <7725085.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: sisilla14@gmail.com References: <7720814.post@talk.nabble.com> <4576E188.5000200@sun.com> <7725085.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org Hello Again, It seems that my java program ignores the NOT NULL column constraints that I have declared on my derby database table. What am I missing here? I appreciate any help. Thanks, Sisilla Sisilla wrote: > > Thank you, Lance, for your help. I installed the driver in common/lib, and > the JSP is working now. I greatly appreciate this. ~Sisilla > > Lance J. Andersen wrote: >> >> Where is the driver installed in tomcat and how are you accessing it? >> Normally the drivers would go in common/lib and you would create an >> entry in the server.xml to access the DataSource >> >> Sisilla wrote: >>> Hello All, >>> >>> I am using a java program (code shown below) to insert some records into >>> a >>> derby database table. The method addNewClient is called from a JSP >>> served >>> from Tomcat, but it throws a ClassNotFoundException as well as an SQL >>> Exception. The method is unable to find or load the ClientDriver. I >>> believe >>> my CLASSPATH is set up correctly since I was able to insert the records >>> into >>> the table with a Test.java program I wrote by modifying the code below >>> to >>> contain a main method which I executed it on the command line. >>> >>> What might I be doing wrong here? I am running Derby 10.2.1.6 and Tomcat >>> 5.5.9 on Windows XP Pro. I am also using Netbeans IDE 5.0. I greatly >>> appreciate any help. >>> >>> Thanks, >>> Sisilla >>> >>> package Sales; >>> import java.sql.*; >>> >>> public class NewClient >>> { >>> >>> public NewClient() >>> { >>> } >>> >>> public boolean addNewClient(String company, String industry, String >>> otherindustry, String contact, String countrycode, String areacode, >>> String >>> number, String email, String address1, String address2, String city, >>> String >>> country, String fcountrycode, String fareacode, String fnumber, String >>> website) >>> { >>> // ## DEFINE VARIABLES SECTION ## >>> // define the driver to use >>> String driver = "org.apache.derby.jdbc.ClientDriver"; >>> // the database name >>> String dbName="ETMApp"; >>> // define the Derby connection URL to use >>> String connectionURL = "jdbc:derby://localhost:1527/" + dbName + >>> ";create=true"; >>> >>> Connection conn = null; >>> Statement s; >>> >>> String telephone = countrycode + areacode + number; >>> String fax = fcountrycode + fareacode + fnumber; >>> >>> if (industry == "") >>> industry = otherindustry; >>> >>> String st = "'" + company + "', '" + industry + "', '" + contact + >>> "', >>> '" + telephone + "', '" + email + "', '" + address1 + "', '" + address2 >>> + >>> "', '" + city + "', '" + country + "', '" + fax + "', '" + website + >>> "'"; >>> >>> String createString = "INSERT INTO APP.Client(company, industry, >>> contact, telephone, email, address1, address2, city, country, fax, >>> website) >>> VALUES(" + st + ")"; >>> >>> // Beginning of JDBC code sections >>> // ## LOAD DRIVER SECTION ## >>> >>> try >>> { >>> /* >>> ** Load the Derby driver. >>> ** Catch an error and suggest a CLASSPATH problem >>> */ >>> Class.forName(driver); >>> System.out.println(driver + " loaded. "); >>> } >>> >>> catch(java.lang.ClassNotFoundException e) >>> { >>> System.err.print("ClassNotFoundException: "); >>> System.err.println(e.getMessage()); >>> System.out.println("\n >>> Please check your CLASSPATH >>> variable >>> <<<\n"); >>> } >>> >>> // ## BOOT DATABASE SECTION ## >>> try >>> { >>> // Create (if needed) and connect to the database >>> conn = DriverManager.getConnection(connectionURL, "app", ""); >>> System.out.println("Connected to database " + dbName); >>> >>> // Create a statement to issue INSERT commands. >>> s = conn.createStatement(); >>> System.out.println (" . . . . INSERTing VALUES into TABLE >>> Client"); >>> if (s.executeUpdate(createString) != 0) //INSERT >>> successful >>> return true; >>> else >>> return false; //INSERT unsuccessful >>> } >>> >>> catch (Throwable e) >>> { >>> /* Catch all exceptions and pass them to >>> ** the exception reporting method >>> */ >>> System.out.println(" . . . exception >>> thrown:"); >>> errorPrint(e); >>> return false; //INSERT unsuccessful >>> } >>> } >>> >>> // ## DERBY EXCEPTION REPORTING CLASSES ## >>> /*** Exception reporting methods >>> ** with special handling of SQLExceptions >>> ***/ >>> static void errorPrint(Throwable e) >>> { >>> if (e instanceof SQLException) >>> SQLExceptionPrint((SQLException)e); >>> else >>> { >>> System.out.println("A non SQL error occured."); >>> e.printStackTrace(); >>> } >>> }// END errorPrint >>> >>> // Iterates through a stack of SQLExceptions >>> static void SQLExceptionPrint(SQLException sqle) >>> { >>> while (sqle != null) >>> { >>> System.out.println("\n---SQLException Caught---\n"); >>> System.out.println("SQLState: " + (sqle).getSQLState()); >>> System.out.println("Severity: " + (sqle).getErrorCode()); >>> System.out.println("Message: " + (sqle).getMessage()); >>> sqle.printStackTrace(); >>> sqle = sqle.getNextException(); >>> } >>> }// END SQLExceptionPrint >>> >>> } >>> >> >> > > -- View this message in context: http://www.nabble.com/java-method-called-from-a-JSP-cannot-load-ClientDriver-tf2768547.html#a7725706 Sent from the Apache Derby Users mailing list archive at Nabble.com.