Advertisement
xlrnxnlx

[class] DAO

Feb 24th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package tbanco.dao;
  2.  
  3. import java.sql.*;
  4.  
  5. public class DAO {
  6.     protected Connection conn;
  7.     protected Statement state;
  8.     protected ResultSet result;
  9.     protected final String DRIVER = "jdbc:oracle:thin:USUÁRIO/SENHA@//localhost:1521/XE";
  10.     protected final String JDBC = "oracle.jdbc.OracleDriver";
  11.     protected String lastErrorMessage = "";
  12.    
  13.     // <editor-fold defaultstate="collapsed" desc="Connect/Disconnect">
  14.     protected boolean connect() {
  15.         boolean success = false;
  16.         try {
  17.             Class.forName(JDBC);
  18.             conn = DriverManager.getConnection(DRIVER);
  19.             state = conn.createStatement();
  20.             success = true;
  21.         } catch (ClassNotFoundException | SQLException e) {
  22.             /* getMessage getErrorCode */
  23.         }
  24.         return success;
  25.     }
  26.  
  27.     protected boolean disconnect() {
  28.         boolean success = false;
  29.         try {
  30.             conn.close();
  31.             success = true;
  32.         } catch (SQLException e) {
  33.             /* getMessage getErrorCode */
  34.         }
  35.         return success;
  36.     }
  37.  
  38.     public String getLastErrorMessage() {
  39.         return lastErrorMessage;
  40.     }
  41.    
  42.     // </editor-fold>
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement