jndi接続のテスト



  
  
  
  
  1. <%@ page contentType="text/html; charset=gb2312" %> 
  2.  <%@ page import="javax.naming.Context" %>  
  3.  <%@ page import="javax.sql.DataSource"%>  
  4. <%@ page import="javax.naming.InitialContext"%>  
  5. <%@ page import="java.sql.*"%>  
  6. <%  
  7. try{ 
  8.     Context initContext = new InitialContext(); 
  9.     DataSource ds = (DataSource)initContext.lookup("java:/jboss/datasources/MysqlDs"); 
  10.     if(ds!=null) { 
  11.         out.println(" DataSource!"); 
  12.         out.println("<br>");  
  13.         Connection conn = ds.getConnection();  
  14.         Statement stmt=conn.createStatement(); 
  15.         ResultSet rs=stmt.executeQuery("select * from table_person");  
  16.         out.println(" ");  
  17.         out.println("<br>"); 
  18.         while(rs.next()) {  
  19.             out.println("person_name:"+rs.getString("person_name"));  
  20.             out.println("<br>"); }  
  21.         rs.close();  
  22.         stmt.close(); 
  23.         conn.close();  
  24.         } else 
  25.             out.println(" !"); }  
  26.        catch(Exception ne) { 
  27.            out.println(ne);  
  28.            } 
  29.  
  30. %>