Runtime exception if datasource is hand coded manually
Common way to bind JDBC datasource to components in a Creator generated web application is by drag and drop the database tables from the Data Sources node in the Servers tab. However, users can still add JDBC datasources by manually editing the java source or by using a third party library that has JDBC datasource coded inside its classes.
As observed by some users, this fails while deploying the application to the bundled test container. Let us analyze why it happens and finally I'll explain how to work around this.
When the user drag and drop the database table, a RowSet is added to the managed bean (Ex. SessionBean1.java). Simultaneously, the Design Time System creates a reference entry to the Data Source References node of the project. When the user hits the little green button in the toolbar to execute the application, the Deployment Manager kicks in and deploys the application to the bundled appserver. While deploying the application, it also obtains the datasources information from the Data Source References node and adds the datasource info to the JDBC connection pool maintained by the appserver. This way user need not to have to manually add the datasource while testing the application using bundled appserver. Note, user must manually add the datasource, if the application is deployed to another appserver (Ex. a production server).
So, if the datasource is hand coded in the application, corresponding reference entry is not created in the Data Source References node of the project. So the Deployment Manager is not aware of the required connection and does not add the datasource information to the appserver's connection pool, causing a run time SQL exception.
Now, the solution ..
- Get the data source info (may be from the documentation of the third party library) and add the data source to the Data Sources Node in the Servers tab (don't forget to test the connection using "test connection button" in the Add Data Dource dialog).
- Right click on the Data Source References node in the project and select Add Data Source Reference menu item. In the resulting dialog select the recently added datasource (it should appear in the list) and hit add button. Now, the added datasource should appear as a child node to the Data Source References node.

Deploy the application .. and .. no more run time SQL exception!
Posted at 08:36PM Oct 11, 2005 | Permanent link to this entry
Posted by 64.243.24.210 on June 16, 2006 at 12:28 PM PDT #
Posted by Winston Prakash on June 16, 2006 at 02:11 PM PDT #
Posted by 64.243.24.210 on June 19, 2006 at 05:34 AM PDT #
Posted by jose luis on January 12, 2007 at 01:21 PM PST #
Posted by 203.101.40.237 on May 30, 2007 at 02:59 AM PDT #
Posted by asdf on May 30, 2007 at 03:00 AM PDT #
Posted by Vignesh on May 30, 2007 at 03:01 AM PDT #