%@ 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.*" %>
<%!
private static DataSource ds = null;
private static String source = "jdbc/LWYDB";
private static String user = "db2admin";
private static String password = "db2admin";
static {
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) {
System.err.println(e.toString());
}
}
%>
<%
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){}
}
%>