主题:为何抛出异常?
这是个JSP文件:可是每次运行总会抛出一个异常,输出:fff
可是我又照原样写了一个JAVA文件,它就不会抛出异常,请问这是怎么回事?
抛出异常:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.lang.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<% ResultSet rs=null;
Connection con=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:mydb");
}
catch(Exception e)
{out.println("fff");return ;}
try
{ rs=con.createStatement().executeQuery("select *from reg");}
catch(Exception e)
{out.println("ddd");return ;}
try{
while(rs.next())
out.println(rs.getString("username"));}
catch(Exception e)
{out.println("mmm");}
%>
</body>
</html>
JAVA文件《不会抛出
import java.sql.*;
class h{
public static void main(String a[])throws Exception
{
Connection con;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:mydb");
}
catch(Exception e)
{System.out.println("fff");return ;}
try
{ rs=con.createStatement().executeQuery("select *from reg");}
catch(Exception e)
{System.out.println("ddd");return ;}
while(rs.next())
System.out.println(rs.getString("username"));
}}
可是我又照原样写了一个JAVA文件,它就不会抛出异常,请问这是怎么回事?
抛出异常:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.lang.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<% ResultSet rs=null;
Connection con=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:mydb");
}
catch(Exception e)
{out.println("fff");return ;}
try
{ rs=con.createStatement().executeQuery("select *from reg");}
catch(Exception e)
{out.println("ddd");return ;}
try{
while(rs.next())
out.println(rs.getString("username"));}
catch(Exception e)
{out.println("mmm");}
%>
</body>
</html>
JAVA文件《不会抛出
import java.sql.*;
class h{
public static void main(String a[])throws Exception
{
Connection con;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:mydb");
}
catch(Exception e)
{System.out.println("fff");return ;}
try
{ rs=con.createStatement().executeQuery("select *from reg");}
catch(Exception e)
{System.out.println("ddd");return ;}
while(rs.next())
System.out.println(rs.getString("username"));
}}