WEB开发网
开发学院软件开发Java WebSphere Application Server Community Edition... 阅读

WebSphere Application Server Community Edition 中的应用程序日志记录

 2010-05-12 00:00:00 来源:WEB开发网   
核心提示: 清单 3. 缺省 java.util.loggingLoggerlogger=Logger.getLogger(EMPDemo.class.getName());logger.setLevel(Level.FINEST);Connectioncon=null;Statementstmt=null

清单 3. 缺省 java.util.logging

Logger logger = Logger.getLogger(EMPDemo.class.getName()); 
logger.setLevel(Level.FINEST); 
Connection con = null; 
Statement stmt = null; 
  
PrintWriter out = response.getWriter(); 
  
logger.info("Created the PrintWriter on the Response object"); 
  
try { 
  Context initContext = new InitialContext(); 
  Context envContext = Context)initContext.lookup("java:comp/env"); 
  logger.info("Got Initial context: " +envContext); 
  DataSource ds = (DataSource)envContext.lookup("jdbc/DataSource"); 
  logger.info("Got DataSource: " +ds.toString()); 
  con = ds.getConnection(); 
  logger.info("Got Connection: " +con.toString() +"\n"); 
  stmt = con.createStatement(); 
  logger.info("Got Statement : " +stmt); 
  ResultSet rs = stmt.executeQuery("SELECT * FROM EMPLOYEE"); 
  logger.info("Table EMP after SELECT:"); 
 
  out.println("Your EMP table contains the following entries:<BR>"); 
 
  out.println("<table>"); 
  out.println("<tr>"); 
  out.println("<th>Empno</th>"); 
  out.println("<th>Name</th>"); 
  out.println("<th>Job</th>"); 
  out.println("<th>Manager</th>"); 
  out.println("<th>Salary</th>"); 
  out.println("<th>Commission</th>"); 
  out.println("<th>Deptno</th>"); 
  out.println("</tr>"); 
 
    while (rs.next()) { 
      String emp = rs.getString("EMPNO"); 
      String name = rs.getString("ENAME"); 
      String job = rs.getString("JOB"); 
      String mgr = rs.getString("MGR"); 
      String sal = rs.getString("SAL"); 
      String comm = rs.getString("COMM"); 
      String dept = rs.getString("DEPTNO"); 
 
      out.println("<tr>"); 
      out.println("<td>"+emp+"</td>"); 
      out.println("<td>"+name+"</td>"); 
      out.println("<td>"+job+"</td>"); 
      out.println("<td>"+mgr+"</td>"); 
      out.println("<td>"+sal+"</td>"); 
      out.println("<td>"+comm+"</td>"); 
      out.println("<td>"+dept+"</td>"); 
      out.println("</tr>"); 
   
      logger.info(emp + "  " + name + "  " + job); 
   logger.info("  " + mgr + "  " + dept); 
    } 
    out.println("</table>"); 
  
    rs.close(); 
    stmt.close(); 
    con.close(); 
  
  logger.severe("my severe message"); 
   logger.warning("my warning message"); 
   logger.info("my info message"); 
   logger.config("my config message"); 
   logger.fine("my fine message"); 
   logger.finer("my finer message"); 
   logger.finest("my finest message"); 
 
    } 
    catch(java.lang.Exception e) { 
  
      e.printStackTrace(); 
      logger.severe(e.getClass().getName()); 
   logger.severe(e.getMessage()); 
    } 
} 

上一页  2 3 4 5 6 7 8 9 10  下一页

Tags:WebSphere Application Server

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接