Wednesday, February 18, 2009

Referencing the Datasource from the Applcation.

Referencing the Datasoure from the Applcation..



reference the JNDI resource you just configured form the web appllicatoin

To do so

create and entry in the application 's deployment descriptor
(web.xml)



the following to reference the JNDI Datasource in the application's deployment descriptor.

1. In the Projects window, expand the Web Pages > WEB-INF subfolder and double-click web.xml. A graphical editor for the file displays in the Source Editor.




webpage>>>web-INF
webpage>>>web-INF
webpage>>>web-INFwebpage>>>web-INF

webpage>>>web-INF


double click web.xml

double click web.xml


double click web.xml



2. Click the References tab located along the top of the Source Editor. Expand the Resource References heading, then click Add. The Add Resource Reference dialog opens.
3. For Resource Name, enter the resource name that you gave when configuring the JNDI Datasource for the server above (jdbc/IFPWAFCAD). The Description field is optional, but you can enter a human-readable description of the resource, e.g., Database for IFPWAFCAD application. Note that the default resource type is javax.sql.DataSource. Leave all fields that are provided by default and click OK. The new resource is added under the Resource References heading:





Adding the Database Driver's JAR File to the Server

Adding the database driver's JAR file is another step that is vital to enabling the server to communicate with your database. Ordinarily, you would need to locate your database driver's installation directory and copy the mysql-connector-java-5.x-bin.jar file from the driver's root directory into the library folder of the server you are using. Fortunately, the IDE's server management is able to detect at deployment whether the JAR file has been added - and if not, it does so automatically.

In order to demonstrate this, open the Servers window (Choose Tools > Servers). For both GlassFish and Tomcat, the IDE provides a JDBC driver deployment option. If the option is enabled, it initiates a check to determine whether any drivers are required for the server's deployed applications. In the case of MySQL, if the driver is required and it is missing, the IDE's bundled driver is deployed to the appropriate location on the server.


Tomcat

1. Open the Servers window by choosing Tools > Servers from main menu.
2. Select Tomcat 6.0 in the left panel, then click the Deployment tab in the main pane. Notice that the Enable JDBC driver deployment option is selected by default.



# Click the Classes tab. This tab displays all of the JAR files contained in the server's lib folder. If you have already deployed your project to the server, you will find that the mysql-connector-java-5.x-bin.jar file is listed here. If not, click Close to exit the Servers window, and deploy your project now (next step).
# In the Projects window, choose Deploy (or Undeploy and Deploy) from the right-click menu of the project node. You can view progress in the IDE's Output window (Ctrl-4; ⌘-4 on Mac). The output indicates that the MySQL driver is deployed to /lib in the Tomcat server.

No comments:

Post a Comment