<%--显示数据记录--%>
<%@ page contentType="text/html; charset=GB2312"%>

<html>

<!-- ´´½¨Ò»¸ö HTMLÒ³ÄÜÓÃÀ´ºÍÓû§µÄÇëÇó½øÐн»»¥
-->

<head>
<title>连接数据库</title>
</head>
<body bgcolor=#FFFFFF>
<font face="Helvetica">

<h2>
<font color=#DB1260>
½»»¥²éѯ
</font>
</h2>
<%//引入类库%>
<%@ page import="weblogic.db.jdbc.*,java.sql.*
" %>

<%!
//ÉùÃ÷Êý¾Ý¿âÁ¬½Ó±äÁ¿
Connection conn  = null;
//ÉùÃ÷Êý¾Ý¿âjdbcÇý¶¯±äÁ¿
String jdbcClass ="sun.jdbc.odbc.JdbcOdbcDriver";
//ÉùÃ÷Êý¾Ý¿âurl±äÁ¿
String jdbcURL   = "jdbc:odbc:jdbcsm";


//ÉùÃ÷Êý¾Ý¿âÁ¬½Ó·½·¨
public Connection getCon() {
  
try {
  
//¼ÓÔØÊý¾Ý¿âÇý¶¯³ÌÐò
    Class.forName(jdbcClass).newInstance();
    
//½¨Á¢Êý¾Ý¿âÁ¬½Ó
    conn = DriverManager.getConnection(jdbcURL);
  } 
catch (Exception e) {}
  
return conn;
}
%>

<%
try {
//½¨Á¢Êý¾Ý¿âÁ¬½Ó
  conn = getCon();
  
if (conn != null) {
  
//´´½¨Ö´ÐÐsqlÓï¾äµÄ¶ÔÏó±äÁ¿
    Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
     
//Ö´ÐÐsqlÓï¾ä£¬»ñµÃ½á¹û¼¯
    stmt.execute("select * from authors");
    ResultSet ds 
= stmt.getResultSet();
    
//»ñÈ¡ÇëÇó²ÎÊý  
    String myURL  = request.getRequestURI();
    String person 
= request.getParameter("id");
      
    
if (person == null) {
    
//ÁгöËùÓнá¹û
%>

      
<table border=1 cellpadding=5>
        
<th>Employee no</th>
        
<th>Select a name</th>
        
<th>Job</th>
        
<th>Manager</th>
        
<th>Date of hire</th>
        
<th>Salary</th>
        
<th>Commission</th>
        
<th>Dept no</th>

<%
      
while (ds.next()) {
%>

        
<tr>
          
<td><%= ds.getString(1!= null ? ds.getString(1) : "&nbsp;" %></td>
          
<td><%= ds.getString(2!= null ? ds.getString(2) : "&nbsp;" %></td>
          
<td><%= ds.getString(3!= null ? ds.getString(3) : "&nbsp;" %></td>
          
<td><%= ds.getString(4!= null ? ds.getString(4) : "&nbsp;" %></td>
          
<td><%= ds.getString(5!= null ? ds.getString(5) : "&nbsp;" %></td>
          
<td><%= ds.getString(6!= null ? ds.getString(6) : "&nbsp;" %></td>
          
<td><%= ds.getString(7!= null ? ds.getString(7) : "&nbsp;" %></td>
          
<td><%= ds.getString(8!= null ? ds.getString(8) : "&nbsp;" %></td>
        
</tr>

<%
      }
%>      

      
</table>

<%
    
//¹Ø±ÕÊý¾Ý¿âºÍÁ¬½Ó
      ds.close();
      conn.close();
      out.flush();
    }
    
else {
    
//´òÓ¡ÇëÇóijһ¸öÈ˵Ľá¹û
%>    

      
<p>
      
<b>½»»¥²éѯ½á¹û</b>:
      
<p>
      ÄãÑ¡ÔñµÄÈËÊÇ: 
<%= person %>

<%
    }
  }
  
else {
  
//Êý¾Ý¿âÁ¬½Ó´íÎó
    out.print("Êý¾Ý¿â²»¿ÉÓá£");
  }
catch (Exception e) {
//Òì³£´¦Àí
  out.print("Exception: " + e);
}
%>


</font>
</body>
</html>