Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 ResultSet返回为null?
neil99





发贴: 19
积分: 0
于 2006-04-04 14:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
<jsp:useBean id="sqlb" scope="page" class="packages.util.DataBase" />

<%@ page import="java.sql.*;" %>
<%
    try{
      String str2="select * from ta";     
      
      ResultSet rs=sqlb.executeSearch(str2);

      if(rs==null)
        out.print("空");
      
      while(rs.next())
      out.println(rs.getInt("id")+"\t"+rs.getString("name"));

      
      rs.close();
      sqlb.closeStmt();
      sqlb.closeConn();
      
    }catch(Exception e){
    out.println(e.getMessage());
    }
    
    %>

为什么在jsp中ResultSet 返回为 空 呢
packages.util.DataBase在应用程序中测试是好的啊
//********************************************************

package packages.util;

import java.sql.*;
public class DataBase {

  String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=./data/demo.mdb";
  Connection conn=null;
  Statement stmt=null;
  ResultSet rs=null;
  String user=null;
  String password=null;

  public DataBase(){
    try{    
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      //Connection conn=DriverManager.getConnection(strurl,"","") ;
      //Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
      //Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    }catch(java.lang.ClassNotFoundException cnfe){
    System.err.println(cnfe);
    }
  
  }

  public void executeChange(String sqlStr){//记录更新,插入,删除
    try{
      conn=DriverManager.getConnection(strurl,user,password);
      stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
      stmt.executeUpdate(sqlStr);
      stmt.close();
      conn.close();  
    }catch(SQLException ex){
    System.err.println("sql_data.executeUpdate:"+ex.getMessage());
  }
  }

  public ResultSet executeSearch(String sqlStr){//记录查询
    try{
      conn=DriverManager.getConnection(strurl,user,password);
      stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
      rs=stmt.executeQuery(sqlStr);

      
    }catch(SQLException ex){
    System.err.println("sql_data.executeQuery:"+ex.getMessage());
    }
    return rs;  
  }

  public void closeStmt(){
    try{
      stmt.close();
    }catch(SQLException e){
      e.printStackTrace();
    }
  }

  public void closeConn(){
    try{
      conn.close();
  }catch(SQLException e){
    e.printStackTrace();
  }
  }

  
}

为什么在jsp中ResultSet 返回为空呢
packages.util.DataBase在应用程序中测试是好的啊
是不是demo.mdb路径放错了? 我放在 myapp/data/demo.mdb 下
myapp下是test.jsp




初学者与<书>

话题树型展开
人气 标题 作者 字数 发贴时间
22005 ResultSet返回为null? neil99 2464 2006-04-04 14:21
19820 Re:ResultSet返回为null? Jcat 132 2006-04-04 15:01
19522 Re:ResultSet返回为null? neil99 7 2006-04-15 10:28
20749 Re:ResultSet返回为null? neil99 3145 2006-04-15 10:48
19567 Re:ResultSet返回为null? neil99 26 2006-04-04 15:15
19585 Re:ResultSet返回为null? Jcat 17 2006-04-04 17:13
19561 Re:ResultSet返回为null? neil99 65 2006-04-04 17:49
19603 Re:ResultSet返回为null? chy305 14 2006-04-04 22:10
19921 Re:ResultSet返回为null? Jcat 16 2006-04-05 08:19
19443 Re:ResultSet返回为null? neil99 20 2006-04-05 08:51
19850 Re:ResultSet返回为null? tomcatexpert 166 2006-04-11 18:16
19551 Re:ResultSet返回为null? neil99 18 2006-04-05 08:53
19472 Re:ResultSet返回为null? neil99 29 2006-04-15 10:14

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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