Saturday, November 4, 2006

JDBC via JNDI

// define sql query
String sql = "select firstname from users";

// initialize database connection objects
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

// get JNDI JDBC connection
InitialContext ctxt = new InitialContext();
DataSource ds = (DataSource) ctxt.lookup("jdbc/TrackIt");
conn = ds.getConnection();

// run sql objects
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);

// retrieve results
while (rs.next()) {
rs.getInt("firstname"));
}

3 comments:

mpegjohn said...

Good, basic setup, Just what I needed.

Anonymous said...

[url=http://www.ukgamingstore.co.uk/]gaming computers[/url]

[url=http://www.ukgamingstore.co.uk/intel-core-i7-gaming-computers]intel core i7 gaming computer uk[/url]

[url=http://www.ukgamingstore.co.uk/intel-core-i3-gaming-laptops]core i3 gaming laptop uk[/url]

[url=http://www.ukgamingstore.co.uk/gaming-mouse-pads]gaming mouse pads[/url]

Anonymous said...

Article writing is also a fun, if you know after that you can write
if not it is complicated to write.

Also visit my webpage legalsoundz.com