Topic: useBean 连接数据库问提

  Print this page

1.useBean 连接数据库问提 Copy to clipboard
Posted by: neil99
Posted on: 2006-03-30 09:48

<%@ page contentType="text/html; charset=gb2312" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="content-language" content="gb2312" />
</head>
<body>
<%@ page language="java" %>
<jsp:useBean id="sqlb" scope="page" class="packages.util.DataBase" />

<%@ page import="java.sql.*;" %>
<%

try{
String str2="select * from ta";
out.println(str2);

ResultSet rs=sqlb.executeSearch(str2);

if(rs.next()) //这里开始不打印结果?
out.println('2');
rs.beforeFirst();
while(rs.next())
out.println(rs.getInt("id")+"\t"+rs.getString("name"));


rs.close();
sqlb.closeStmt();
sqlb.closeConn();
}catch(Exception e){}

%>

结束
</body>
</html>

为什么读不出数据库的内容呢?也没显示错误啊
直接跳到显示 "结束"
packages.util.DataBase 在程序中测试是好的啊

2.Re:useBean 连接数据库问提 [Re: neil99] Copy to clipboard
Posted by: hoden_w
Posted on: 2006-03-30 17:29

看不懂楼主想要干什么?
if(rs.next()) {//这里开始不打印结果?是不是数据库里面没有东西??
out.println('2');
}
rs.beforeFirst();
while(rs.next()){
out.println(rs.getInt("id")+"\t"+rs.getString("name"));
}

rs.close();
sqlb.closeStmt();
sqlb.closeConn();

3.Re:useBean 连接数据库问提 [Re: neil99] Copy to clipboard
Posted by: neil99
Posted on: 2006-03-30 19:36

不是了
if(rs.next()) {
out.println('2');
}

这里我没有删除掉.没有的.

rs.beforeFirst();
while(rs.next()){
out.println(rs.getInt("id")+"\t"+rs.getString("name"));
}
才是打印数据库内容
就是显示不出来


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923