日期:2014-05-18  浏览次数:20837 次

哪里错了?新手,等待中,想了半天了
import   java.sql.Connection;
import   java.sql.DriverManager;
import   java.sql.ResultSet;
import   java.sql.SQLException;
import   java.sql.Statement;
import   java.util.Properties;

import   javax.naming.Context;
import   javax.naming.InitialContext;
import   javax.sql.DataSource;

//import   org.apache.commons.dbcp.BasicDataSource;

/**
  *  
  */
public   class   DataBase   {
private   static   DataSource   dts   =   null;

public   static   Connection   getConnection()   {
Connection   conn   =   null;
try   {
if   (dts   ==   null)   {
Class.forName(   "oracle.jdbc.driver.OracleDriver "   );  
String   url   =   "jdbc:oracle:thin:@************* ";  
conn   =   DriverManager.getConnection(url, "test ",   "test ");  
}
//conn   =   dts.getConnection();
}   catch   (Exception   e)   {
e.printStackTrace();
}

return   conn;
}

public   static   void   closeConnection(Connection   con,   Statement   stmt,
ResultSet   rs)   {
try   {
if   (rs   !=   null)   {
rs.close();
rs   =   null;
}
if   (stmt   !=   null)   {
stmt.close();
stmt   =   null;
}
if   (con   !=   null)   {
con.close();
con   =   null;
}

}   catch   (Exception   e)   {
e.printStackTrace();
}   finally   {
rs   =   null;
stmt   =   null;
con   =   null;
}
}
}
上面是写的DataBase,下面是JSP
<%@page   contentType= "text/html;charset=GBK "   import= "java.sql.* "%>
<html>
<title> 用户数据 </title>
<body>
<%        

Connection   conn=null;
Statement   stmt=null;
ResultSet   rs=null;

try{  

conn   =   DataBase.getConnection();
String   query= "select   *from   EMP ";
rs=stmt.executeQuery(query);
%>
<h4> 取出信息 </h4>
<table   border= "1 ">
<tr>
<th> TEMPO </th> <th> ENAME </th> <th> JOB </th> <th> MGR </th> <th> HIREDATE </th> <th> SAL </th> <th> COMM </th> <th> DEPTNO </th>
</tr>
<%
while(rs.next()){
out.println( " <tr> ");
out.println( " <td> "+rs.getString( "TEMPO ")+ " </td> ");
out.println( " <td> "+rs.getString( "ENAME ")+ " </td> ");
out.println( " <td> "+rs.getString( "JOB ")+ " </td> ");
out.println( " <td> "+rs.getString( "MGR ")+ " </td> ");
out.println( " <td> "+rs.getString( "HIREDATE ")+ &quo