Book Image

JDBC 4.0 and Oracle JDeveloper for J2EE Development

Book Image

JDBC 4.0 and Oracle JDeveloper for J2EE Development

Overview of this book

Table of Contents (20 chapters)
JDBC 4.0 and Oracle JDeveloper for J2EE Development
Credits
About the Author
About the Reviewer
Preface

Connecting to a Database from a Web Application


If a Java application is used to connect to a database, a JDBC connection may be obtained using the getConnection() method of the DriverManager class. If a JDBC connection is to be obtained in a web application, a data source with a JNDI naming service binding must be configured in an application server, such as the OC4J embedded in JDeveloper IDE. The data source object configured in data-sources.xml may be used in a Servlet or JSP in JDeveloper. In this section, we will connect to MySQL database using the managed data source we configured in the previous section. First, we need to create a project in JDeveloper with File | New. In the New Gallery window, select General | Applications in Categories and Application in Items and click on OK. Specify the Application Name in the Create Application window and click on the OK button. Specify the Project Name in the Create Project window and click on the OK button. A new project is added to the...