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.
by Deepak Vohra
Feb 6, 2007
Page 5 of 5
Configuring WebLogic with SQL Server
Create a WebLogic Server domain using the Configuration Wizard. The default domain that gets created is base_domain.
Start the WebLogic Admin Server for the base_domain by double-clicking on C:\BEA\user_projects\domains\base_domain\startWebLogic script.
Access the WebLogic server administration console with the URL http://localhost:7001/console or by clicking Administration Console link in the Welcome page. Specify the username as weblogic and Password as weblogic to login to the Administration Console.
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.
On the Data Sources page, click the New button to configure a new data source (see Figure 27).
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.
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.
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.
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.
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.
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.