RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


J2EE and SQL Server: Making a JDBC Connection : Page 5

Using a SQL Server back end with a Java application server may sound like an unnatural proposition but there's no need to bow to such arbitrary limitations. In this article you'll get step-by-step instructions on making a JDBC connection between the four most popular Java application servers and Microsoft SQL Server.


Configuring WebLogic with SQL Server

  1. Create a WebLogic Server domain using the Configuration Wizard. The default domain that gets created is base_domain.
  2. Start the WebLogic Admin Server for the base_domain by double-clicking on C:\BEA\user_projects\domains\base_domain\startWebLogic script.
  3. Access the WebLogic server administration console with the URL http://localhost:7001/consoleor by clicking Administration Console link in the Welcome page. Specify the username as weblogic and Password as weblogic to login to the Administration Console.
  4. To configure a JDBC Connection pool, select the Services>JDBC>Data Sources link (see Figure 26). Click on the Lock & Edit button to add a datasource.
    Figure 26. JDBC data sources.
    Figure 27. Adding a new data source.
    Figure 28. Specifying the data source properties.
  5. On the Data Sources page, click the New button to configure a new data source (see Figure 27).
  6. In the dialog that follows, specify a datasource name and a JNDI name. In the Database Type, select MS SQL Server (see Figure 28). You'll also be asked to specify the database driver. BEA provides its own MS SQL Server drivers, which are pre-configured to work with WebLogic server; therefore, you don't need to add a JDBC driver JAR file to the WebLogic server classpath. However, if you prefer to use Microsoft's SQL Server driver JAR files, then you should select them at this time. Click on the Next button.
  7. At this point the Transaction Options page is displayed. If you want to use global transactions select an XA-driver, which supports global transactions by default, in the previous dialog. Global transactions are transactions that span over multiple databases. If a non-XA driver is selected, you must configure the data source to support global transactions by selecting the Supports Global Transactions checkbox and a transaction protocol. A discussion on transactions is outside the scope of this article. Please refer the WebLogic Server JDBC documentation. Click on the Next button.
  8. In the Connection Properties dialog specify the database name where prompted. If you plan to use the default database name, specify NA in the Database Name field. Specify the host name as localhost (see Figure 29). Specify the ports as explained in the sidebar "Obtaining the Port Values." The username is sa and the password is whatever you use to login to the database. Click on the Next button.

  9. Figure 29. Specifying connection properties.
    Figure 30. Testing the connection.
  10. On the Test Database Connection page the driver class name is specified as weblogic.jdbc.sqlserver.SQLServerDriver. The URL, port values, and username/password are the same as in the earlier section. The URL is specified as jdbc:bea:sqlserver://localhost:1155. However, if the default database is used, delete property databaseName=NA.

    Now you can click on the Test Configuration button to test the JDBC data source. If the JDBC connection is properly established, a message "Connection test succeeded" is displayed (see Figure 30). Click Next and in the Select Targets dialog, select the AdminServer (see Figure 31), and click on the Finish button.

    Figure 31. Selecting the target server.
    Figure 32. A new data source.

    This creates a data source for SQL Server and adds it to the Data Sources page as shown in Figure 32. Click on the Activate Changes button to activate the datasource configuration.

Get Started
If you want an open source application server, use the JBoss application server. JBoss is also the easiest to configure with SQL Server. Otherwise, go with whichever application server fits best in your environment. By configuring an application server with SQL Server, J2EE applications with a JDBC component may be developed on your SQL Server back end.

Deepak Vohra is an O'Reilly technical reviewer, who reviewed the book WebLogic: The Definitive Guide. He's also a NuBean consultant and web developer, and is a Sun Certified Java 1.4 Programmer and Sun Certified Web Component Developer for J2EE.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date