import java.sql.*;
public class Zh
{  public static void main(String args[])
   {  Connection con;Statement sql; ResultSet rs;
      try {  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
          }
     catch(ClassNotFoundException e)
          {  System.out.println(""+e);
          }
      try
          { 
             con=DriverManager.getConnection("jdbc:odbc:djd","","");
             sql=con.createStatement();
             rs=sql.executeQuery("SELECT * FROM zhanghui");
             while(rs.next())
             { String  number=rs.getString(1);
               String  name=rs.getString(2);  
               Date    date=rs.getDate(3);
               int     math=rs.getInt("数学");
               int  physics=rs.getInt("物理"); 
               int  english=rs.getInt("英语");
               System.out.println("学号:"+number); 
               System.out.print("  姓名:"+name);
               System.out.print("  出生:"+date);
               System.out.print("  数学:"+math);
               System.out.print("  物理:"+physics);  
               System.out.print("  英语:"+english);
             }
            con.close();
           }
      catch(SQLException e1) {}
   
   }    
}  

解决方案 »

  1.   

    啊?怎么这样写?有创意,虽然try{}catch{}可以嵌套,但最好不要这样写,除非特殊需要,原因,一、容易出错。二、维护不方便,你想啊,如果代码多,要维护的话,谁愿意看这么多的异常处理方式,可以多写几个方法,表现出java的灵活性。
      

  2.   

    可以的:你试试:没有错   
    catch(SQLException e1) {
              System.out.println(e1);
           }