Migrating Java Studio Creator 2 (u1) applications that use Oracle datasources to NetBeans 6.
Introduction
NetBeans 6 provides a migration path for Java Studio Creator 2 users. There is a detailed Migration Guide for Creator users at netbeans.org.
The migration process involves opening a copy of your Creator project in NetBeans 6, expanding the project node, wating for the 'Updating Legacy Project' process to end and thats it. Seamless as this process is there are a few cases where projects might not get completely migrated easily.
The Problem
One of these issues is the migration of a Creator project that uses an Oracle datasource. The reason being that Creator bundled DataDirect drivers for Oracle databases. NetBeans 6 does not. On top of that the DataDirect drivers can only be used from inside Creator. As a result users might end up in a situation where their oracle connection is not migrated properly.
This is what would typically happen if such a project was opened in NB6:
On expanding the project node in the projects window, the "Updating Legacy Projects" process would start. However once it finished the Data Source References node would be badged red and a pop-up message would come up indicating that data source references are missing and need to be resolved. If a page that uses this datasource is opened the Design view would not open and throw a SQL exception.
The Workaround
Here are list of steps that can be used to workaround this situation:
- First of all download the freely available JDBC driver for Oracle from Oracle's website here.
- Once downloaded switch to the Services tab in NetBeans and right click on the Databases->Drivers node to add Drivers. Add the downloaded Oracle driver.
- Now right click on the Databases Node to add a New Connection. This connection will connect to your Oracle database through the downloaded driver.
- Once the dialog comes up select the Oracle Driver from the drop down list.
- Username and password should be the same as the one you used in Creator.
- The url is slightly different. This is the template you should use: jdbc:oracle:thin:@SERVERNAME:PORT:SID
- Notice that the DataDirect drivers in Creator used a slightly different URL syntax. (i.e. jdbc:sun:oracle....)
- Once done try connecting and make sure you can view all the tables in your database.
- If you haven't already opened your Creator project in NetBeans 6 open the Projects tab in NetBeans and go ahead and do it now. Expand the project node and wait for the Updating Legacy projects process to end. (You might recieve Warning messages indicating that you need to Resolve Missing Data Sources. For now ignore them)
- Now Expand the Server Resources node under your project node and open the sun-resources.xml file as shown in the figure below.
Location of sun-resources.xml File
 |
- The sun-resources.xml file typically contains 2 things. A datasource and a connection pool definition. When the application is deployed on the application server this file is used to register these resources on the server.
- At this point however your sun-resources.xml file contains information that is specific to the DataDirect drivers. To correct this you need to make 3 changes:
- Under the jdbc-connection-pool tag there is a property with name="URL". Currently thevalueattribute contains the URL in the format used by the DataDirect drivers. The should be changed to use the following format jdbc:oracle:thin:@Server Name:PORT:SID. For eg.
- <property name="URL" value="jdbc:sun:oracle://ServerName:1521;SID=sid"/>, should be changed to :
- <property name="URL" value="jdbc:sun:oracle://ServerName:1521:sid"/>
- Similarly the value of the driverClass property should be changed. For eg.
- <property name="driverClass" value="com.sun.sql.jdbc.oracle.OracleDriver"/>, should be changed to :
- <property name="driverClass" value="oracle.jdbc.OracleDriver"/>
- And lastly the jdbc-connection-pool tag has an attribute datasource-classname.(You might need to scroll to the right to see it.) The value for this attribute should be changed like this:
- datasource-classname="com.sun.sql.jdbcx.oracle.OracleDataSource", should be changed to :
- datasource-classname="oracle.jdbc.pool.OracleDataSource"
- Now save and close the sun-resources.xml file and Clean and Build your project. Open a page that uses the datasource. If it still throws SQL exceptions click on the Refresh button in the design view. If you're still seeing the error or the project is badged red you might want to close and reopen the project.
- Thats it! The project should start working fine after this point.
Note:
Before opening a legacy project in NB6 it is recommended to :
- Make a copy of your project , and
- Delete the private.xml file under yourProject/nbproject/private/ folder.