db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Dudziak <tom...@gmail.com>
Subject Re: "conglomerate does not exist" error
Date Sun, 13 Nov 2005 19:11:35 GMT
On 11/11/05, Susan Cline <home4slc@pacbell.net> wrote:

> I got this to work using the following configuration:
>
> Tomcat 5.5.9 with these edits to the server.xml file:
>
> <Host>
> ....
>
> <Context path="/DerbyClasspathTest"
> docBase="DerbyClasspathTest" debug="5"
> reloadable="true" crossContext="true">
>
>   <!-- Datasource for Derby database -->
>   <Resource name="jdbc/derby"
> type="javax.sql.DataSource" auth="Container"
> description="Derby database"
> driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
> url="jdbc:derby:classpath:derbydb" username="APP"
> password="APP" maxActive="4" maxIdle="2"/>
>
> </Context>
>
> </Host>
>
> I placed the derby.jar file in
> $TOMCAT_HOME/common/lib.
>
> I added this entry to my web.xml:
>
> <resource-ref>
>      <res-ref-name>jdbc/derby</res-ref-name>
>      <res-type>javax.sql.DataSource</res-type>
>      <res-auth>Container</res-auth>
>  </resource-ref>

This approach however ties me to Tomcat and makes it necessary to
change the server environment neither of which I can afford, because
my webapp is supposed to be a simple drop-in into any servlet
container (Jetty, Tomcat, JRun, you name it).

> I created a simple servlet and put this in it's init
> method for a simple test:
>
> DataSource ds = null;
> Connection conn = null;
> try {
>         // Obtain our environment naming context
>         Context initCtx = new InitialContext();
>         Context envCtx = (Context)
> initCtx.lookup("java:comp/env");
>
>         // Look up our data source
>         ds = (DataSource) envCtx.lookup("jdbc/derby");
>         initCtx.close();
>         envCtx.close();
>         } catch (NamingException namingExc) {
>                 namingExc.printStackTrace();
>         }
>
>         try {
>                 conn = ds.getConnection();
>                 String query = "select * from APP.foo";
>
>                 Statement stmt = conn.createStatement();
>                 ResultSet results = stmt.executeQuery(query);
>                 ResultSetMetaData rsmd = results.getMetaData();
>                 int numberCols = rsmd.getColumnCount();
>
>                 while (results.next()) {
>                 for (int i = 1; i <= numberCols; i++) {
>                                                 System.out.println("Select * from APP.foo
is: "
> + results.getString(i));
>
>                 }
>         }
>                 results.close();
>                 stmt.close();
>                 } catch (SQLException sqlExcept) {
>                                 sqlExcept.printStackTrace();
>                         }
>
>         }
>
> I created a database, derbydb using ij and created a
> table foo in it and inserted one row.  I then imported
> it using Eclipse to the WEB-INF/classes directory.

I think this is the crucial point. As I wrote before, my approach
worked without problems when I ran ij on the database before starting
the webapp (there was no need to make Tomcat aware of the database).
However I'd like to create the database via the url (which is done
automatically upon first connect), not via an external tool.

> As I mentioned before I haven't used Spring so I don't
> know if this is complicating anything.  But I have
> verified that you can connect to the database using
> the database connection URL you wanted to, using the
> classpath identifier.
>
> (By the way, thanks!  I need that for something I'm
> working on too!)

You should definitely checkout Spring, makes dealing with databases so
much easier. Specifically, you don't need to deal with the server.xml
anymore, JDBC handling (or other ORMs like iBATIS, OJB or Hibernate)
are nicely abstracted for you, and on top of it all you get really
nice automatic transaction handling for which you don't have to write
a single line of code.

thanks anyway ;-)
Tom

Mime
View raw message