这段代码有什么不足之处?try {Connection conn = ...;Statement stmt = ...;ResultSet rs = stmt.executeQuery("select * from table1");while(rs.next()) {}} catch(Exception ex) {}

这段代码有什么不足之处?

try {

Connection conn = ...;

Statement stmt = ...;

ResultSet rs = stmt.executeQuery("select * from table1");

while(rs.next()) {

}

} catch(Exception ex) {

}


相关考题:

【问题2】(7分)该商务网站的计数器部分代码如下,请根据题目说明,将空缺的代码补充完整。%set conn= server.createobject("adodb.connection")(7) .provider="sqloledb"provstr="serveF127.0.0.1;database= (8) L;uid=sa;pwd=9857452"conn_.open provstrset rs=conn.Execute("select*from counter")……conn.Execute"Update counter set counteFcounter+l,today=o,statdtm=date(),daynum=daynum+l, yesterday=" rs("today")"”conn.Execute" (9) into yesday(yesday,stats) values(…yesday”’,”rs(”today”)”)”……application. ( 10)if rs("top”)rs("today") thenconn.Execute"Update counter set counter=counter+1,today=today+1, [top]="rs("today")""elseconn.Execute"Update counter set counter=counter+1,today=today+1"end if(11) .unlockend ifcounters= (12)today= (13)yesterday= rs("yesterday")rs.closesetrs= nothingconn.closesetconn=nothing%document.write('font style="FONT-SIZE: 12px;COLOR: #000000;"总共访问量:%=counters%,今日访问:%=today%,昨日访问:%=yesterday%/font');

分析以下代码。public static void test(string ConnectString){System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();conn.ConnectionString = ConnectString;try{conn.Open();…….}catch(Exception Ex){MessageBox.Show(Ex.ToString());}finally{if (!conn.State.Equals(ConnectionState.Closed))conn.Close();}请问1)以上代码可以正确使用连接池吗?2)以上代码所使用的异常处理方法,是否所有在test方法内的异常都可以被捕捉并显示出来?

static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?() A、 test endB、 Compilation fails.C、 test runtime endD、 test exception endE、 A Throwable is thrown by main at runtime.

假定表table1中phone列有空值,则select count(*) from table1与select count(phone) from table1相等吗? ()A、相等B、不相等

Which the statement is true?()A、 The Error class is a Runtime Exception.B、 No exceptions are subclasses of Error.C、 Any statement that may throw an Error must be enclosed in a try block.D、 any statement that may throw an Exception must be enclosed in a try block.E、 Any statement that may throw an Runtime Exception must be enclosed in a try block.

static void test() {  try {  String x=null;  System.out.print(x.toString() +“ “);  }  finally { System.out.print(“finally “); }  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  }  What is the result?() A、 nullB、 finallyC、 null finallyD、 Compilation fails.E、 finally exception

程序员将可能发生异常的代码放在()块中,后面紧跟着一个或多个()块。A、catch、tryB、try、catchC、try、exceptionD、exception、try

面是创建Statement接口并执行executeUpdate方法的代码片段:      conn=DriverManager.getConnection("jdbc:odbc:book","","");     stmt=conn.createStatement();  String strsql="insert into book values(’TP003’, ’ASP.NET’,’李’,’清华出版社’,35)";  n=stmt.executeUpdate(strsql);   代码执行成功后n的值为()。A、 1B、 0C、 -1D、 一个整数

try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()  A、 finishedB、 ExceptionC、 Compilation fails.D、 Arithmetic Exception

public static void main(String[] args) {  try {  args=null;  args[0] = “test”;  System.out.println(args[0]);  } catch (Exception ex) {  System.out.println(”Exception”);  } catch (NullPointerException npe) {  System.out.println(”NullPointerException”);  }  }  What is the result?() A、 testB、 ExceptionC、 Compilation fails.D、 NullPointerException

现有:  void topGo()  {      try  {  middleGo();  }  catch  (Exception e)  {      System.out.print("catch");      }      }  void middleGo()  throws Exception  {     go();  system.out.print("late middle");     }  void go()  throws ExceptiOn  {     throw new Exception();     } 如果调用 topGo () ,则结果为:() A、 late middleB、 catchC、 late middle catchD、 catch Iate middle

static void test() throws Error {  if (true) throw new AssertionError();  System.out.print(”test “);  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  System.out.print(”elld “);  }  What is the result?() A、 endB、 Compilation fails.C、 exception endD、 exception test endE、 A Throwable is thrown by main.F、 An Exception is thrown by main.

现有:  class Birds {  public static void main (String  []  args)  {   try {  throw new Exception () ;    } catch (Exception e) {   try {   throw new Exception () ;  }  catch  (Exception e2)  {  System.out.print ("inner           "); }   System. out.print ( "middle" ) ;    }  System.out.print ("outer") ;    }    }  结果是()A、 inner outerB、 middle outerC、 inner middle outerD、.编译失败

class Birds {  public static void main(String [] args) {  try {  throw new Exception();  } catch (Exception e) { try {  throw new Exception();  } catch (Exception e2) { System.out.print("inner "); }  System.out.print("middle "); }  System.out.print("outer ");  }  }  结果为:()  A、innerB、inner outerC、middle outerD、inner middle outer

Assume the custom tag my:errorProne always throws a java.lang.RuntimeException with the message "Filenot found." An error page has been configured for this JSP page. Which option prevents the exceptionthrown by my:errorProne from invoking the error page mechanism, and outputs the message "File notfound" in the response?()A、c:try catch="ex"my:errorProne //c:try${ex.message}B、c:catch var="ex"my:errorProne //c:catch${ex.message}C、c:try. my:errorProne /. /c:try. c:catch var="ex" /. ${ex.message}D、c:try. my:errorProne /. c:catch var="ex" /. ${ex.message}. /c:try

Your application demands frequent connection and disconnection from the database. You have three listener processes that are listening for the database PROD. While setting up the connect string using Oracle Enterprise Manager 10g Database Control, which two options would you select to balance the connection load across all the listener processes?()A、Use only the first address.B、Try one address,selected at random.C、Try each address,in order,until one succeeds.D、Try each address,randomly,until one succeeds.

You are creating a stored procedure that will delete data from the Contact table in a SQL Server 2005 database. The stored procedure includes the following Transact-SQL statement to handle any errors that occur. BEGIN TRY   BEGIN TRANSACTION   DELETE FROM Person.Contact WHERE ContactID = @ContactID COMMIT TRANSACTION END TRY   BEGIN CATCH   DECLARE @ErrorMessage nvarchar(2000) DECLARE @ErrorSeverity int DECLARE @ErrorState int SELECT @ErrorMessage = ERROR MESSAGE(),@ErrorSeverity=ERROR SEVERITY(),@ErrorState = ERROR STATE() RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState) END CATCH;      You test the stored procedure and discover that it leaves open transactions. You need to modify the stored procedure so that it properly handles the open transactions. What should you do?()A、Add a COMMIT TRANSACTION command to the CATCH block.B、Remove the COMMIT TRANSACTION command from the TRY block.C、Add a ROLLBACK TRANSACTION command to the CATCH block.D、Add a ROLLBACK TRANSACTION command to the TRY block.

单选题static void test() {  try {  String x=null;  System.out.print(x.toString() +“ “);  }  finally { System.out.print(“finally “); }  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  }  What is the result?()A nullB finallyC null finallyD Compilation fails.E finally exception

单选题面是创建Statement接口并执行executeUpdate方法的代码片段:      conn=DriverManager.getConnection("jdbc:odbc:book","","");     stmt=conn.createStatement();  String strsql="insert into book values(’TP003’, ’ASP.NET’,’李’,’清华出版社’,35)";  n=stmt.executeUpdate(strsql);   代码执行成功后n的值为()。A 1B 0C -1D 一个整数

单选题public static void main(String[] args) {  try {  args=null;  args[0] = “test”;  System.out.println(args[0]);  } catch (Exception ex) {  System.out.println(”Exception”);  } catch (NullPointerException npe) {  System.out.println(”NullPointerException”);  }  }  What is the result?()A testB ExceptionC Compilation fails.D NullPointerException

单选题现有:  class Birds {  public static void main (String  []  args)  {   try {  throw new Exception () ;    } catch (Exception e) {   try {   throw new Exception () ;  }  catch  (Exception e2)  {  System.out.print ("inner           "); }   System. out.print ( "middle" ) ;    }  System.out.print ("outer") ;    }    }  结果是()A inner outerB middle outerC inner middle outerD.编译失败

单选题static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?()A test endB Compilation fails.C test runtime endD test exception endE A Throwable is thrown by main at runtime.

单选题现有:  void topGo()  {      try  {  middleGo();  }  catch  (Exception e)  {      System.out.print("catch");      }      }  void middleGo()  throws Exception  {     go();  system.out.print("late middle");     }  void go()  throws ExceptiOn  {     throw new Exception();     } 如果调用 topGo () ,则结果为:()A late middleB catchC late middle catchD catch Iate middle

单选题Assume the custom tag my:errorProne always throws a java.lang.RuntimeException with the message "Filenot found." An error page has been configured for this JSP page. Which option prevents the exceptionthrown by my:errorProne from invoking the error page mechanism, and outputs the message "File notfound" in the response?()Ac:try catch=exmy:errorProne //c:try${ex.message}Bc:catch var=exmy:errorProne //c:catch${ex.message}Cc:try. my:errorProne /. /c:try. c:catch var=ex /. ${ex.message}Dc:try. my:errorProne /. c:catch var=ex /. ${ex.message}. /c:try

单选题假定表table1中phone列有空值,则select count(*) from table1与select count(phone) from table1相等吗? ()A相等B不相等

单选题try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()A finishedB ExceptionC Compilation fails.D Arithmetic Exception

单选题Which the statement is true?()A The Error class is a Runtime Exception.B No exceptions are subclasses of Error.C Any statement that may throw an Error must be enclosed in a try block.D any statement that may throw an Exception must be enclosed in a try block.E Any statement that may throw an Runtime Exception must be enclosed in a try block.