String filesiteno = request.getParameter("filesiteno");
String usertruthname = request.getParameter("usertruthname");
usertruthname = new String(usertruthname.getBytes("ISO8859_1"));
System.out.println("filesiteno=" + filesiteno);
System.out.println("usertruthname=" + usertruthname);
String sql = "";
sql = "select BF_User.usertruthname,ST_POWER.SiteNO from ST_POWER,BF_User";
if (filesiteno != "") {
if (sql.indexOf("where") == -1) {
sql = sql + " where filesiteno=" + filesiteno + "";
} else {
sql = sql + " and filesiteno=" + filesiteno + " ";
}
}
if (usertruthname != "") {
if (sql.indexOf("where") == -1) {
sql = sql + " where usertruthname like '%" + usertruthname + "%' ";
} else {
sql = sql + " and usertruthname like '%" + usertruthname + "%' ";
}
}
Connect.getConnection();
Connection conn = null;
PreparedStatement pstmt = null;             
System.out.println("所执行的语句为" + sql);
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();

Vector vector = new Vector();
while (rs.next()) {
Info info = new Info();
info.setsiteno(rs.getString("filesiteno"));
info.setusertruthname(rs.getString("usertruthname"));
vector.add(info);
}
为什么程序走到标红处就出现NULL错误呢?急求

解决方案 »

  1.   

    Connection conn = null;
    PreparedStatement pstmt = null;   
    System.out.println("所执行的语句为" + sql);
    pstmt = conn.prepareStatement(sql);你根本就没有得到数据库连接的对象。
      

  2.   

    Connection  PreparedStatement 2个对象都是空 你都没创建就调用它的方法
      

  3.   

    没实例化Connection对象

    Connect.getConnection();
    Connection conn = null;
    写成
    Connection conn = Connect.getConnection();
      

  4.   

    +1  conn, pstmt对象都是null,肯定会报空指针异常呀!
      

  5.   

    Connection conn = Connect.getConnection();
    PreparedStatement pstmt = null;
      

  6.   

    Connection conn = Connect.getConnection();