Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 85142 invoked from network); 6 Dec 2006 15:28:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Dec 2006 15:28:36 -0000 Received: (qmail 65783 invoked by uid 500); 6 Dec 2006 15:28:43 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 65758 invoked by uid 500); 6 Dec 2006 15:28:42 -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 65747 invoked by uid 99); 6 Dec 2006 15:28:42 -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 07:28:42 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [192.18.98.36] (HELO brmea-mail-4.sun.com) (192.18.98.36) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Dec 2006 07:28:30 -0800 Received: from fe-amer-04.sun.com ([192.18.108.178]) by brmea-mail-4.sun.com (8.13.6+Sun/8.12.9) with ESMTP id kB6FS9vW011306 for ; Wed, 6 Dec 2006 08:28:09 -0700 (MST) Received: from conversion-daemon.mail-amer.sun.com by mail-amer.sun.com (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) id <0J9U00J01YRW6Y00@mail-amer.sun.com> (original mail from Lance.Andersen@Sun.COM) for derby-user@db.apache.org; Wed, 06 Dec 2006 08:28:09 -0700 (MST) Received: from [129.150.65.61] by mail-amer.sun.com (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPSA id <0J9U00GSMYYVOX53@mail-amer.sun.com> for derby-user@db.apache.org; Wed, 06 Dec 2006 08:28:08 -0700 (MST) Date: Wed, 06 Dec 2006 10:28:08 -0500 From: "Lance J. Andersen" Subject: Re: java method called from a JSP cannot load ClientDriver In-reply-to: <7720814.post@talk.nabble.com> Sender: Lance.Andersen@Sun.COM To: Derby Discussion Message-id: <4576E188.5000200@sun.com> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7BIT References: <7720814.post@talk.nabble.com> User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) X-Virus-Checked: Checked by ClamAV on apache.org 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 > > } >