<%@ page contentType="text/html; charset=euc-kr" %> <%@ page import="java.sql.*,com.ibm.db2.jdbc.app.stdext.javax.sql.*,com.ibm.ejs.dbm.jdbcext.*, javax.naming.*" %> <% DataSource ds = null; String source = "jdbc/LWYDB"; String user = "db2admin"; String password = "db2admin"; try { java.util.Hashtable props = new java.util.Hashtable(); props.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory"); Context ctx = null; try { ctx = new InitialContext(props); ds = (DataSource)ctx.lookup(source); } finally { if ( ctx != null ) ctx.close(); } } catch (Exception e) { out.println(e.toString()); return; } Connection conn = null; Statement stmt = null; try { conn = ds.getConnection(user, password); stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from emp"); while(rs.next()){ out.println("empno=" + rs.getString(1) + ", ename=" + rs.getString(2) + "
"); } rs.close(); } catch(Exception e){ out.println(e.toString()); } finally { if ( stmt != null ) try { stmt.close();}catch(Exception e){} if ( conn != null ) try { conn.close();}catch(Exception e){} } %>