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

Let's say there is a WebSphere data source that has a JNDI of jdbc/mySQL.


In this scenario, you would add the following to WEB-INF/web.xml.



J2C authentication alias

see IBM WebSphere - JDBC data source and J2C alias


SQL query

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 e231a in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |