Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package db;
- /**
- * Created by Administrator on 2017-02-14.
- */
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class DBUtil {
- static {
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static Connection getConnection() {
- Connection con = null;
- try {
- con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "root");
- return con;
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return con;
- }
- // 자원반납
- public static void dataClose(Connection c, PreparedStatement p) {
- try {
- if (c != null) {
- c.close();
- }
- if (p != null) {
- p.close();
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- // 자원반납
- public static void dataClose(Connection c, PreparedStatement p, ResultSet s) {
- try {
- if (c != null) {
- c.close();
- }
- if (p != null) {
- p.close();
- }
- if (s != null) {
- s.close();
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement