FreeKB - Configure an app to use a WebSphere JDBC
Configure an app to use a WebSphere JDBC

Home > Search

This assumes that the JDBC data source is setup in WebSphere, which means that WebSphere will have the JDBC provider, the data source, and the J2C alias. Now, you want your app to use the WebSphere JDBC, so that your app can make a connection to a database. 

Let's say the WebSphere data source has a JNDI of jdbc/mySQL. In this scenario, you would add the following to WEB-INF/web.xml.



Here is an example of a JSP page that makes a connection to the database associated with jdbc/mySQL.

<%@ taglib uri="" prefix="sql" %>
<%@ taglib uri="" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<sql:query var="myvar" dataSource="jdbc/mySQL">
    select * from foo;


Now, if you manually deploy the application, there will be a prompt where you will map the data source to JNDI jdbc/mySQL.


A much better option is to place the ibm-web-bnd.xml file in the WEB-INF folder of your WAR to define the JNDI. If you do this, you will not be prompted to define the JNDI when manually deploying an app to WebSphere. Instead, the application will use the data source defined in ibm-web-bnd.xml.

<?xml version="1.0" encoding="UTF-8"?>

	<resource-ref name="jdbc/mySQL" binding-name="jdbc/mySQL" />




Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 1d3f1 in the box below so that we can be sure you are a human.