高手们嫩港我解决一下这个jsp问题吗?万分感谢!!!

[复制链接]
查看11 | 回复6 | 2007-10-20 08:38:44 | 显示全部楼层 |阅读模式
下面这段代码为什么执行结果就不对呢,报的错是:
An error occurred at line: 7 in the jsp file: /TitleList.jsp
Generated servlet error:
C cannot be resolved
……
但是把第一个try……catch结构去掉,把下面两句话放在第二个try 里面或这两句话不用try结构,都正确。这是为什么呀,我觉得没错阿,请教各位帮我解答一下。
代码:
…………………………
try {
Connection C = DriverManager.getConnection(sConnStr);
stmt=C.createStatement();
}
catch (SQLException E) {

out.println("111111 &quot

;

}
try{
ResultSet rs=stmt.executeQuery("select * from guestbook&quot

;
rs.next();
out.println("&quot

;
out.println("&quot

;
out.println(rs.getString(1));
out.println("&quot

;
out.println("&quot

;
out.print(rs.getString(2));
out.println("&quot

;
out.println("&quot

;
out.print(rs.getString(3));
out.println("&quot

;
rs.close();
stmt.close();
C.close();
}
catch (SQLException E) {
out.println("SQLException:111111 " + E.getMessage());
out.println("SQLState: " + E.getSQLState());
out.println("VendorError: " + E.getErrorCode());
}
……………………
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
Connection C 的C,
在下面的try里是不可见的
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
You should declare Connection C outside the try Block
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
必须在try{}catch{}外先声明C和stmt,在第二个块里才能用否则第二个try{}里面不认识。
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
Scope
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
java的语法基础不扎实哦
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
Thanks
无比感激Thanks
无比感激Thanks
无比感激Thanks
无比感激
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行