advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Obtaining the Port Values
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 2/5 | Rate this item | 1 user has rated this item.
Email this articleEmail this article
J2EE and SQL Server: Making a JDBC Connection (cont'd)
Configuring JDeveloper with SQL Server
  1. 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).
  2.  
    Figure 8. Adding a library.
     
    Figure 9. Adding a user library.
     
    Figure 10. Creating a library.
  3. In the Add Library dialog, select the User node, and click on the New button (see Figure 9).
  4. 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).
     
    Figure 11. A new library.
     
    Figure 12. Specifying a connection type.
     
    Figure 13. Registering a JDBC driver.
  5. 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.
  6. 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.
  7. In the Authentication dialog specify sa as the Username and the Password as the password used to install the SQL Server database.
  8. 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.
  9. 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.")
  10.  
    Figure 14. Specifying connection parameters.
     
    Figure 15. Testing the connection.
     
    Figure 16. A new database connection.
  11. 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:

<resource-ref>
  <res-ref-name>jdbc/SQLServerConnectionDS</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>
advertisement
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)
 initialContext.lookup("java:comp/env/jdbc/SQLServerConnectionDS");
   java.sql.Connection conn = ds.getConnection();
Previous Page: Introduction Next Page: Configuring JBoss with SQL Server
Page 1: IntroductionPage 4: Configuring WebSphere with SQL Server
Page 2: Configuring JDeveloper with SQL ServerPage 5: Configuring WebLogic with SQL Server
Page 3: Configuring JBoss with SQL Server 
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES