JAVA空指针异常,请高手们帮忙,这个问题我好长时间没有解决了,多谢了。 http://expert.csdn.net/Expert/topic/2003/2003607.xml?temp=.9213373楼主偷了我的分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 出现这种异常一般是你的getter和setter方法中没有对NUll时的处理机制。比如java.sql.Date date=ndate;有可能ndate本身为空,又传给了date,然后不加处理就对date进行如下转换date.toString();结果就是出现空指针异常。主要是编写代码不规范和经验欠缺所致。仔细检查你的程序吧! jsp_servlet._test1.__testsql._jspService(__testsql.java:124)在jb中生成的文件里面可以打开上面的文件看124行就行了 你的代码肯定要出问题。1,rs很容易过期。2,数据库的善后处理不好。给你一个比较保险的。 //输入:sql语句 //输出:查询的结果集 public CachedRowSet executeQuery(String sql) throws java.sql.SQLException { CachedRowSet cst = new CachedRowSet(); try { conn = db.getConnection(); ps = conn.createStatement(); rs = ps.executeQuery(sql); cst.populate(rs); rs.close(); } catch (SQLException e) { System.out.println(e.getMessage()); } finally { db.CleanConnection(conn, ps, rs); } return cst;//离线结果急(你的问题出在这里,返回的rs不能保存,应该用一个离线的结果急来保存) } //输入:要执行的sql语句 //输出:无 public void execute(String sql)throws SQLException { try { conn = db.getConnection(); ps = conn.createStatement(); ps.execute(sql); ps.close(); } catch (SQLException e) { throw new SQLException(e.getMessage()); } finally { try { db.CleanConnection(conn, ps, rs); } catch (SQLException e) { throw new SQLException(e.getMessage()); } } }而且应该用finally来善后处理 你的代码肯定要出问题。1,rs很容易过期。2,数据库的善后处理不好。给你一个比较保险的。 //输入:sql语句 //输出:查询的结果集 public CachedRowSet executeQuery(String sql) throws java.sql.SQLException { CachedRowSet cst = new CachedRowSet(); try { conn = db.getConnection(); ps = conn.createStatement(); rs = ps.executeQuery(sql); cst.populate(rs); rs.close(); } catch (SQLException e) { System.out.println(e.getMessage()); } finally { db.CleanConnection(conn, ps, rs); } return cst;//离线结果急(你的问题出在这里,返回的rs不能保存,应该用一个离线的结果急来保存) } //输入:要执行的sql语句 //输出:无 public void execute(String sql)throws SQLException { try { conn = db.getConnection(); ps = conn.createStatement(); ps.execute(sql); ps.close(); } catch (SQLException e) { throw new SQLException(e.getMessage()); } finally { try { db.CleanConnection(conn, ps, rs); } catch (SQLException e) { throw new SQLException(e.getMessage()); } } }而且应该用finally来善后处理估计错误的地方就是 Struts HTML 标签库 中标签属性的问题 JBuilder如果自定义标签 jspSmartUpload下载中文名文件的解决办法!(高分相求)在线等!急 dreamweaver中的代码提示有时候有,有时候没有,请问高手知道怎么回事吗? 一个有关jsp的问题??? 关于中文乱码问题?求大神帮我瞧瞧 在线等!急 请较高手一个有关resin安装的问题? 高分请教jsp基本问题 jdk1.4是不是和sql server 2000 jdbc不兼容? servlet返回文本(类型text/plain)时中文乱码了? 连数据库出现的错误,请大家帮忙啊!一解决问题就结帖,哈哈
java.sql.Date date=ndate;
有可能ndate本身为空,又传给了date,
然后不加处理就对date进行如下转换date.toString();结果就是出现空指针异常。
主要是编写代码不规范和经验欠缺所致。仔细检查你的程序吧!
在jb中生成的文件里面可以打开上面的文件看124行就行了
1,rs很容易过期。
2,数据库的善后处理不好。
给你一个比较保险的。
//输入:sql语句
//输出:查询的结果集
public CachedRowSet executeQuery(String sql) throws java.sql.SQLException {
CachedRowSet cst = new CachedRowSet();
try {
conn = db.getConnection();
ps = conn.createStatement();
rs = ps.executeQuery(sql);
cst.populate(rs);
rs.close();
}
catch (SQLException e) {
System.out.println(e.getMessage());
}
finally {
db.CleanConnection(conn, ps, rs);
}
return cst;//离线结果急(你的问题出在这里,返回的rs不能保存,应该用一个离线的结果急来保存)
}
//输入:要执行的sql语句
//输出:无
public void execute(String sql)throws SQLException {
try {
conn = db.getConnection();
ps = conn.createStatement();
ps.execute(sql);
ps.close();
}
catch (SQLException e) {
throw new SQLException(e.getMessage());
}
finally {
try {
db.CleanConnection(conn, ps, rs);
}
catch (SQLException e) {
throw new SQLException(e.getMessage());
}
}
}而且应该用finally来善后处理
1,rs很容易过期。
2,数据库的善后处理不好。
给你一个比较保险的。
//输入:sql语句
//输出:查询的结果集
public CachedRowSet executeQuery(String sql) throws java.sql.SQLException {
CachedRowSet cst = new CachedRowSet();
try {
conn = db.getConnection();
ps = conn.createStatement();
rs = ps.executeQuery(sql);
cst.populate(rs);
rs.close();
}
catch (SQLException e) {
System.out.println(e.getMessage());
}
finally {
db.CleanConnection(conn, ps, rs);
}
return cst;//离线结果急(你的问题出在这里,返回的rs不能保存,应该用一个离线的结果急来保存)
}
//输入:要执行的sql语句
//输出:无
public void execute(String sql)throws SQLException {
try {
conn = db.getConnection();
ps = conn.createStatement();
ps.execute(sql);
ps.close();
}
catch (SQLException e) {
throw new SQLException(e.getMessage());
}
finally {
try {
db.CleanConnection(conn, ps, rs);
}
catch (SQLException e) {
throw new SQLException(e.getMessage());
}
}
}而且应该用finally来善后处理
估计错误的地方就是