jave learns the third section of the code

package com.neusoft.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcOracleTest {

	/**
	 * @param args
	 */

	public static void main(String[] args) {

		// 2.建立同数据库的连接
		// url:统一资源定位符
		String url = "jdbc:oracle:thin:@10.25.85.247:1521:orcl";
		String user = "scott";
		String password = "tiger";
		Connection con = null;
		Statement st = null;
		String sql = "select * from DEPT";
		String sql1 = "delete from USERTEST";
		ResultSet rs = null;
		PreparedStatement pst = null;
 关闭资源
		try {
			if (rs != null) {
				rs.close();
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			if (st != null) {
				st.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			if (pst != null) {
				pst.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			if (con != null) {
				con.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

Guess you like

Origin blog.csdn.net/u010256329/article/details/9423877