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.