Configuring JDeveloper with SQL Server
- As I mentioned in the previous section, the first step is to add the JAR file for the JDBC driver class to the classpath by creating a new library for the SQL Server JAR files. Open JDeveloper and Select Tools>Default Project Properties. In the Default Project Properties dialog select the Libraries node and click the Add Library button (see Figure 8).
- In the Add Library dialog, select the User node, and click on the New button (see Figure 9).
- In the Create Library dialog specify a Library Name, such as "SQLServer." Select the Class Path node and click the Add Entry button. For SQL Server 2000, add the msbase.jar, mssqlserver.jar, and msutil.jar JAR files to this dialog. For SQL Server 2005 Express, add sqljdbc.jar (see Figure 10) and click OK. Click OK several more times until you’ve exited the Libraries dialog (see Figure 11).
- Next, configure a JDBC connection with the SQL Server database. In the Connections Navigator right-click on the Database node and select New Database Connection to start the Create Database Connection wizard.
- In the Type dialog specify a Connection Name and select 'Third Party JDBC Driver' in the Connection Type field (see Figure 12). Click on the Next button.
- In the Authentication dialog specify sa as the Username and the Password as the password used to install the SQL Server database.
- In the Connection dialog, locate the Driver Class field and specify the driver class, com.microsoft.jdbc.sqlserver.SQLServerDriver (2000), or com.microsoft.sqlserver.jdbc.SQLServerDriver (2005 Express). Click on New to add a driver class. In the Register JDBC Driver dialog, specify driver class in Driver Class field (see Figure 13). In the Library field select the SQLServer library that you configured in the last section (I called mine "SQLServer"). Click OK to add it.
- In the URL field specify the connection URL as shown in Figure 14. This portion of the process is the same regardless of which application server you are using and the specific URL and port values required are explained in the sidebar "Obtaining the Port Values.")
- Now you can test the connection using the Test Connection button (see Figure 15). If you've done everything correctly, a JDBC connection is established with the database. Click on the Finish button.
You’ve added a node for this connection to the Database node in the Connections Navigator as shown in Figure 16
. This connection is also available as jdbc/SQLServerConnectionDS
datasource in a JSP or a servlet. To obtain a connection from the datasource in a JSP, add to the web.xml of the JSP application:
You can obtain a JDBC connection in a JSP or a servlet using this code:
InitialContext initialContext = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)
java.sql.Connection conn = ds.getConnection();