Skip to content

Commit

Permalink
java异常处理
Browse files Browse the repository at this point in the history
java异常处理
liangjian66 committed Apr 28, 2022
1 parent 91601dc commit c5373e6
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions Java学习笔记.md
Original file line number Diff line number Diff line change
@@ -2,3 +2,4 @@

### Java中的异常处理

* 在程序出错误的时候,Java支持异常,将错误信息封装起来,并让程序跳出正常的处理流程,交给异常处理部分去处理
35 changes: 23 additions & 12 deletions src/Test.java
Original file line number Diff line number Diff line change
@@ -52,15 +52,26 @@ public class Test {
public static void main(String[] args) throws ClassNotFoundException, SQLException {




// try {
// int[] arr = new int[1];
// arr[1] = 9;
// }catch (Exception ex){
// ex.printStackTrace();
// }

Class.forName("");

int[] arr = new int[1];
arr[1] = 9;

try {
System.out.println("异常处理");

}catch (Exception eo){

}
}

public void connect(){
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
@@ -81,15 +92,15 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti


String sql = "select * from user_tab where name = 'hanxiao'";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery(sql);
while (resultSet.next()){
System.out.print("[");
System.out.print( resultSet.getInt("id")+"\t");
System.out.print( resultSet.getString("name")+"\t");
System.out.print( resultSet.getInt("age")+"\t");
System.out.println("]");
}
// PreparedStatement preparedStatement = connection.prepareStatement(sql);
// ResultSet resultSet = preparedStatement.executeQuery(sql);
// while (resultSet.next()){
// System.out.print("[");
// System.out.print( resultSet.getInt("id")+"\t");
// System.out.print( resultSet.getString("name")+"\t");
// System.out.print( resultSet.getInt("age")+"\t");
// System.out.println("]");
// }

}

0 comments on commit c5373e6

Please sign in to comment.