首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

数据库数据输出替空白

2011-12-19 
数据库数据输出为空白代码是这样的:%@pagecontentType text/htmlcharsetgb2312 language java im

数据库数据输出为空白
代码是这样的:
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<%
final   String   DBDRIVER   =   "com.microsoft.jdbc.sqlserver.SQLServerDriver "   ;  
final   String   DBURL   =   "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myjob ";
response.setCharacterEncoding( "GBK ");
Connection   conn   =   null   ;  
ResultSet   rs   =   null   ;  
String   name=null;
String   password=null;
String   user= "sa ";
String   pass= " ";
//String   name1=new   String(request.getParameter( "name ").getBytes( "ISO8859_1 ")).trim();
Statement   st=null;
PreparedStatement   stat=null;
boolean   flag=true;
Class.forName(DBDRIVER)   ;  
conn   =   DriverManager.getConnection(DBURL,user,pass)   ;  
st=conn.createStatement();
rs   =   st.executeQuery( "select   email   from   user1   where   name= '11 ' "   )   ;  
rs.close();                
conn.close();  
%>
<table   width= "100% "   height= "400 "   border= "1 ">
    <tr>
        <td> <jsp:include   page= "update.jsp "   flush= "true "> </jsp:include> </td>
        <td> <table   width= "100% "   height= "81% "   border= "1 ">
            <tr>
                <td> &nbsp; </td>
            </tr>
            <tr>
                <td> <table   width= "200 "   border= "1 ">
                    <tr>
                        <td> 用户名 </td>
                        <td> <%=rs.getString( "email ")%> </td>
                    </tr>
                    <tr>
                        <td> 联系电话 </td>
                        <td> &nbsp; </td>
                    </tr>
                    <tr>
                        <td> E-MAIL </td>
                        <td> &nbsp; </td>


                    </tr>
                    <tr>
                        <td> 年龄 </td>
                        <td> &nbsp; </td>
                    </tr>
                    <tr>
                        <td> &nbsp; </td>
                        <td> &nbsp; </td>
                    </tr>
                    <tr>
                        <td> &nbsp; </td>
                        <td> &nbsp; </td>
                    </tr>
                    <tr>
                        <td> &nbsp; </td>
                        <td> &nbsp; </td>
                    </tr>
                    <tr>
                        <td> &nbsp; </td>
                        <td> &nbsp; </td>
                    </tr>
                </table> </td>
            </tr>
            <tr>
                <td> &nbsp; </td>
            </tr>
        </table> </td>
        <td> &nbsp; </td>
    </tr>
</table>

</body>
</html>
问题是:
    访问此页面的时候输出为空白,网页的框架也不见了,哪位高手帮忙看看,先谢过了。

[解决办法]
你的rs是不是应该拿到最下面页面输出后再关阿
[解决办法]
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<%
final String DBDRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver " ;
final String DBURL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myjob ";
response.setCharacterEncoding( "GBK ");


Connection conn = null ;
ResultSet rs = null ;
String name=null;
String password=null;
String user= "sa ";
String pass= " ";
//String name1=new String(request.getParameter( "name ").getBytes( "ISO8859_1 ")).trim();
Statement st=null;
PreparedStatement stat=null;
boolean flag=true;
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,user,pass) ;
st=conn.createStatement();
rs = st.executeQuery( "select email from user1 where name= '11 ' " ) ;

%>
<table width= "100% " height= "400 " border= "1 ">
<tr>
<td> <jsp:include page= "update.jsp " flush= "true "> </jsp:include> </td>
<td> <table width= "100% " height= "81% " border= "1 ">
<tr>
<td> &nbsp; </td>
</tr>
<tr>
<td> <table width= "200 " border= "1 ">
<tr>
<td> 用户名 </td>
<td> <%=rs.getString( "email ")%> </td>
</tr>
<tr>
<td> 联系电话 </td>
<td> &nbsp; </td>
</tr>
<tr>
<td> E-MAIL </td>
<td> &nbsp; </td>
</tr>
<tr>
<td> 年龄 </td>
<td> &nbsp; </td>
</tr>
<tr>
<td> &nbsp; </td>
<td> &nbsp; </td>
</tr>
<tr>
<td> &nbsp; </td>
<td> &nbsp; </td>
</tr>
<tr>
<td> &nbsp; </td>
<td> &nbsp; </td>
</tr>
<tr>
<td> &nbsp; </td>
<td> &nbsp; </td>
</tr>
</table> </td>
</tr>
<tr>
<td> &nbsp; </td>
</tr>
</table> </td>
<td> &nbsp; </td>
</tr>
</table>
<%
rs.close();
conn.close();
%>
</body>
</html>

[解决办法]
晕 你RS关的太早了结果集都清空了
[解决办法]
rs关早了
另外你在rs = st.executeQuery( "select email from user1 where name= '11 ' " ) ; 后面加个输出看看 如果out.println能输出 那估计就是字符格式的问题
[解决办法]
缺少rs.next();
导致rs.getString()异常

热点排行