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();
}
}