<% @ Page ContentType = "Text / HTML; Charset = GBK"%> <% @ page import = "java.sql. *"%> <% @ page import = "javax.sql. *"%> <% @ Page Import = "javax.naming. *"%>
title> head> <% / / copied from the document weblogic 8 Context ctx = null; Hashtable ht = new Hashtable (); ht.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put (Context.PROVIDER_URL, "t3: // 127.0.0.1:7001 ":// ht.put (context.security_principal," admin "); // ht.put (Context.security_credentials," 11111111 "); connection conn = null; statement stmt = null; ResultSet RS = null; try {ctx = new initialcontext (ht); DataSource DS = (DataSource) ctx.lookup ("ejbpool"); conn = ds.getConnection (); stmt = conn.createstatement (); stmt.execute ("SELECT * from accounts "); rs = stmt.getResultset (); while (rs.next ()) {out.println (rs.getstring (1) " ___ "); Out.Println (rs.getstring (2) "___"); out.println (rs.getstring (3) "
");} stmt.close (); stmt = null; conn.close (); conn = null;} catch (Exceptio Ne) {OUT.PRINTLN ("Error !! Err!");} finally {try {ctx.close ();} catch (exception e) {Out.println ("CTX Err!");} Try {IF rs! = null ()} catch (exception e) {Out.println ("RS ERR!");} Try {if (stmt! = null) stmt.close ();} catch (Exception E ) {OUT.PRINTLN ("STMT ERR!");} Try {if (conn! = null) Conn.close ();} catch (exception e) {Out.println ("Conn Err!");}}% > Body> <