一个jsp访问数据库的问题
文件testdb.jsp的源代码:
<%@ page contentType= "text/html; charset=gb2312 " language= "java "%>
<%@page import= "java.sql.*,javax.sql.*,javax.naming.*,java.io.* "%>
<html>
<head>
<title>
</title>
</head>
<body>
<jsp:useBean id= "db " scope= "application " class= "db.db " />
<%
String sql = "select pointid,road from gx_dsx ";
ResultSet rs = db.executeQuery(sql);
rs.last();
//out.print(rs.getType()+ " <br> ");
while(rs.next()){
out.print(rs.getString( "pointid "));
out.print( " <br> ");
}
%>
</body>
</html>
其中的javabean,db的源代码:
package db;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.util.*;
public class db
{
DataSource ds=null;
Context initCtx=null;
Context ctx=null;
Connection conn =null;
public db(){
try{
initCtx = new InitialContext();
ctx = (Context) initCtx.lookup( "java:comp/env ");
ds = (DataSource) ctx.lookup( "oracleDBPOOL ");
conn = ds.getConnection();
}
catch (
SQLException e) {}
catch (NamingException e) {}
}
protected void finalize( ){
try{conn.close();}catch(Exception e){}
}
//查询记录
public ResultSet executeQuery(String sql){
ResultSet rs = null;
try{
Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
&nbs