Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. package db;
  2.  
  3. /**
  4. * Created by Administrator on 2017-02-14.
  5. */
  6.  
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12.  
  13. public class DBUtil {
  14.  
  15. static {
  16. try {
  17. Class.forName("oracle.jdbc.driver.OracleDriver");
  18. } catch (ClassNotFoundException e) {
  19. // TODO Auto-generated catch block
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. public static Connection getConnection() {
  25. Connection con = null;
  26.  
  27. try {
  28. con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "root");
  29. return con;
  30. } catch (SQLException e) {
  31. // TODO Auto-generated catch block
  32. e.printStackTrace();
  33. }
  34.  
  35. return con;
  36. }
  37.  
  38. // 자원반납
  39. public static void dataClose(Connection c, PreparedStatement p) {
  40.  
  41. try {
  42. if (c != null) {
  43. c.close();
  44. }
  45. if (p != null) {
  46. p.close();
  47. }
  48.  
  49. } catch (SQLException e) {
  50. // TODO Auto-generated catch block
  51. e.printStackTrace();
  52. }
  53. }
  54.  
  55. // 자원반납
  56. public static void dataClose(Connection c, PreparedStatement p, ResultSet s) {
  57.  
  58. try {
  59. if (c != null) {
  60. c.close();
  61. }
  62. if (p != null) {
  63. p.close();
  64. }
  65. if (s != null) {
  66. s.close();
  67. }
  68.  
  69. } catch (SQLException e) {
  70. // TODO Auto-generated catch block
  71. e.printStackTrace();
  72. }
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement