The below code gets a connection from the websphere application server for a created data source.

___________________________________________________________

package com.iewf.resource;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import javax.sql.DataSource;

public class DataSourceHelper {

public static void main(String args[]) throws NamingException, SQLException{

InitialContext ctx = new InitialContext();

javax.sql.DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myDS");

//where jdbc/myDS is the name of the resource reference

//java.sql.Connection conn1 = ds.getConnection();

java.sql.Connection conn = ds.getConnection("user", "password");

//where user and password are the user id and password for the connection

Statement stmt = conn.createStatement();

String query = "";

ResultSet rs = stmt.executeQuery(query);

while (rs.next()) {

//firstNameList.addElement(rs.getString(1));

}

conn.close();

}

}


Enter your email address:

Delivered by FeedBurner



Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)