读取数据库简单工具类

public class DbUtil {

	private static String db_driver ="oracle.jdbc.driver.OracleDriver";

	private static String db_url = "xx";

	private static String db_userName = "xx";

	private static String db_passWord = "xx";

	public static Connection getConnection() {
		Connection conn = null;

		try {
			Class.forName(db_driver);

			conn = DriverManager.getConnection(db_url, db_userName, db_passWord);

		}
		catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		catch (SQLException e) {
			e.printStackTrace();
		}

		return conn;
	}

	public static void close(Connection conn, PreparedStatement ps, ResultSet rs) {
		if (rs != null) {
			try {
				rs.close();
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (ps != null) {
			try {
				ps.close();
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (conn != null) {
			try {
				conn.close();
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public static void close(Connection conn) {
		if (conn != null) {
			try {
				conn.close();
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}

 

你可能感兴趣的:(java,数据库,工具类)