free web page hit counter
Tuesday Oct 11, 2005

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.

Data Source References node in the Creator project

Deploy the application .. and .. no more run time SQL exception!

Comments:

Can you do that with the jndi jars for doing ldap? I'm kinda stuck trying to get that setup.

Posted by 64.243.24.210 on June 16, 2006 at 12:28 PM PDT #

I need more information about your ldap issue. We are working on a LDAP based data provider for future release.

Posted by Winston Prakash on June 16, 2006 at 02:11 PM PDT #

Well, in short, I'd like to be able to create an authentication page where I can make a drop list and bind that to the list of users from an LDAP database. I can then authenticate the password against that user. Nothing too dificult to do with a custom bean, but the ability to do that from the IDE is pretty nice.

Posted by 64.243.24.210 on June 19, 2006 at 05:34 AM PDT #

Look, i´m new in the netbeans visualweb pack and i have this error when try bound mysql whit my application, this is the error and i don´t now have to do. NOTE: Sorry by my english but i don´t speach your language very well Cannot load JDBC driver class 'com.mysql.jdbc.Driver' java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:760) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) at com.sun.sql.rowset.internal.CachedRowSetXReader.connect(CachedRowSetXReader.java:344) at com.sun.sql.rowset.internal.CachedRowSetXReader.readData(CachedRowSetXReader.java:126) at com.sun.sql.rowset.CachedRowSetXImpl.execute(CachedRowSetXImpl.java:968) at com.sun.sql.rowset.CachedRowSetXImpl.execute(CachedRowSetXImpl.java:1428)

Posted by jose luis on January 12, 2007 at 01:21 PM PST #

great

Posted by 203.101.40.237 on May 30, 2007 at 02:59 AM PDT #

sadf

Posted by asdf on May 30, 2007 at 03:00 AM PDT #

Look, i´m new in the netbeans visualweb pack and i have this error when try bound mysql whit my application, this is the error and i don´t now have to do. NOTE: Sorry by my english but i don´t speach your language very well Cannot load JDBC driver class 'com.mysql.jdbc.Driver' java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:760) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) at com.sun.sql.rowset.internal.CachedRowSetXReader.connect(CachedRowSetXReader.java:344) at com.sun.sql.rowset.internal.CachedRowSetXReader.readData(CachedRowSetXReader.java:126) at com.sun.sql.rowset.CachedRowSetXImpl.execute(CachedRowSetXImpl.java:968) at com.sun.sql.rowset.CachedRowSetXImpl.execute(CachedRowSetXImpl.java:1428)

Posted by Vignesh on May 30, 2007 at 03:01 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed