[JavaSE实验] JDBC and MySQL
if (rs.next()) { System.out.println(rs.getString(1)); } } catch (SQLException ex) { Logger lgr = Logger.getLogger(Version.class.getName()); if (con != null) { con.close(); } } catch (SQLException ex) { Logger lgr = Logger.getLogger(Version.class.getName()); The getString() method retrieves the value of a specified column. The first column has index 1. } catch (SQLException ex) { Logger lgr = Logger.getLogger(Version.class.getName()); lgr.log(Level0 码力 | 23 页 | 2.52 MB | 1 年前3Java 基础之IO 和NIO 补完
get("data/subdir"); try { Path newDir = Files.createDirectory(path); } catch(FileAlreadyExistsException e){ // the directory already exists. } catch (IOException e) { //something else went wrong e.printStackTrace(); properties"); try { Files.copy(sourcePath, destinationPath); } catch(FileAlreadyExistsException e) { //destination file already exists } catch (IOException e) { //something else went wrong e.printStackTrace(); destinationPath, StandardCopyOption.REPLACE_EXISTING); } catch(FileAlreadyExistsException e) { //destination file already exists } catch (IOException e) { //something else went wrong e.printStackTrace();0 码力 | 9 页 | 218.38 KB | 1 年前3Apache Shiro 1.2.x Reference Manual 中文翻译
//无异常,说明就是我们想要的! } catch ( UnknownAccountException uae ) { //username 不存在,给个错误提示? } catch ( IncorrectCredentialsException ice ) { //password 不匹配,再输入? } catch ( LockedAccountException lae ) { //账号锁住了,不能登入。给个提示? } ... 更多类型异常 ... } catch ( AuthenticationException ae ) { //未考虑到的问题 - 错误? } 这里有许多不同类别的异常你可以检测到,也可以抛出你自己异常。详见 AuthenticationException JavaDoc 小贴士: 最好的 login(token); } catch (UnknownAccountException uae) { log.info("There is no user with username of " + token.getPrincipal()); } catch (IncorrectCredentialsException0 码力 | 196 页 | 2.34 MB | 1 年前3Java 应用与开发 - 异常处理
异常处理机制 异常处理结构 O 异常处理结构 1 try { 2 ... //可能产生异常的代码,试图捕获异常 4 } catch (ExceptionName1 e) { 5 ... //当产生 ExceptionName1 型异常时的处��� 7 } catch (ExceptionName2 e) { 8 ... //当产生 ExceptionName2 型异常时的处��� 10 不论 try 代码块中是否发生了异常事件,finally 块中的语句 都会被执行。当 catch 语句块中出现 return 语句时,finally 语句块同样会执行。 大纲 异常的概念及分类 Java 异常处理机制 操作异常对象 发生异常时,系统将自动创建异常类对象,并将作为实参传递给 匹配的 catch 语句块的形参,这样就可以在语句块中操纵该异常 对象。 O 异常类的父类 Throwable 常用,在没有找到适合的异常处理代码时,系统也 会自动调用该方法输出错误信息。 大纲 异常的概念及分类 Java 异常处理机制 操作异常对象 发生异常时,系统将自动创建异常类对象,并将作为实参传递给 匹配的 catch 语句块的形参,这样就可以在语句块中操纵该异常 对象。 O 异常类的父类 Throwable 中定义的方法 getMessage() 返回描述当前异常的详细消息字符串。 printStackTrace()0 码力 | 33 页 | 626.40 KB | 1 年前3《Java 应用与开发》课程讲义 - 王晓东
/ 共 306 页 2.1. JAVA 语言基础 � 2 � 表 2.3 Java 语言的关键字(保留字) abstract assert boolean break byte case catch char class continue default do double else enum extends false final finally float for if implements equals(””)) { 13 System.out.println(”Read: ” + s); 14 s = br.readLine(); 15 } 16 br. close (); 17 } catch (IOException e) { 18 e.printStackTrace(); 19 } 20 } 21 } 对上述程序的几点解释: • System.in 为 InputStream s); 14 s = br.readLine(); } 15 br. close (); 16 } catch (FileNotFoundException e1) { 17 System.err.println(”File not found: ” + fname); 18 } catch (IOException e2) { 19 e2.printStackTrace(); 20 }0 码力 | 330 页 | 6.54 MB | 1 年前3跟我学Shiro - 张开涛
UsernamePasswordToken("zhang", "123"); try { //4、登录,即身份验证 subject.login(token); } catch (AuthenticationException e) { //5、身份验证失败 } Assert.assertEquals(true, subject login(token); } catch (UnknownAccountException e) { error = "用户名/密码错误"; } catch (IncorrectCredentialsException e) { error = "用户名/密码错误"; } catch (AuthenticationException (AuthenticationException e) { //其他错误,比如锁定,如果想单独处理请单独 catch 处理 error = "其他错误:" + e.getMessage(); } if(error != null) {//出错了,返回登录页面 req.setAttribute("error"0 码力 | 219 页 | 4.16 MB | 10 月前3Apache Shiro参考手册中文版
try { currentUser.login(token); } catch (UnknownAccountException uae) { log.info("There is no user with username of " + token.getPrincipal()); } catch(IncorrectCredentialsException ice) { log "); } catch(LockedAccountException lae) { log.info("The account for username " + token.getPrincipal() + " is locked. " + "Please contact your administrator to unlock it."); } // … catch more exceptions exceptions here (maybe custom ones specific to your application? catch (AuthenticationException ae) { //unexpected condition? error? } } //say who they are: //print their identifying principal0 码力 | 92 页 | 1.16 MB | 1 年前3基于 Java EE 的企业应用系统设计 - Spring MVC 03
getServletContext() .getRealPath("/image"), fileName); try { multipartFile.transferTo(imageFile); } catch (IOException e) { e.printStackTrace(); } } } model.addAttribute("product", product); return "ProductDetails"; i); i = bis.read(buffer); } catch (IOException e) { // do something, probably forward to an Error page. } finally { if (bis != null) { try { bis.close(); } catch (IOException e) { if (fis != null) null) { try { fis.close(); } catch (IOException e) { return null; } } } } } } 大纲 Spring 文件上传 Spring 文件下载 Spring 用户登录 监听器 示例:隐藏资源 LoginForm.jsp0 码力 | 40 页 | 651.07 KB | 1 年前3JAVA 应用与开发 - 控制台应用程序设计
equals("")) { 13 System.out.println("Read:␣" + s); 14 s = br.readLine(); 15 } 16 br.close(); 17 } catch (IOException e) { 18 e.printStackTrace(); 19 } 20 } 21 } 15 41 ���程序����� System.in 为 InputStream s); 14 s = br.readLine(); } 15 br.close(); 16 } catch (FileNotFoundException e1) { 17 System.err.println("File␣not␣found:␣" + fname); 18 } catch (IOException e2) { 19 e2.printStackTrace(); 20 } 15 } 16 in.close(); // 关闭 BufferedReader 输入流 17 out.close(); // 关闭连接文件的 PrintWriter 输出流 18 } catch (IOException e) { 19 e.printStackTrace(); 20 } 21 } 22 } 24 41 ���������� 1. 写文件�����文件�������行��出������0 码力 | 63 页 | 2.84 MB | 1 年前3Spring Framwork Data Access v5.3.36 SNAPSHOT
code can actually recover from a transaction failure, the application developer can still choose to catch and handle TransactionException. The salient point is that developers are not forced to do so. The rollback: Java public void resolvePosition() { try { // some business logic... } catch (NoProductInStockException ex) { // trigger rollback programmatically TransactionAspectSupport setRollbackOnly(); } } 24 Kotlin fun resolvePosition() { try { // some business logic... } catch (ex: NoProductInStockException) { // trigger rollback programmatically TransactionAspectSupport0 码力 | 197 页 | 2.76 MB | 1 年前3
共 346 条
- 1
- 2
- 3
- 4
- 5
- 6
- 35