Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tbanco.dao;
- import java.sql.*;
- import tbanco.modelo.Client;
- public class DAOClient extends DAO implements InterfaceDAO {
- private Client client;
- // <editor-fold defaultstate="collapsed" desc="Insert, Delete, Update, Select">
- @Override
- public boolean insert(Object object) {
- boolean success = false;
- if (connect()) {
- this.client = (Client)object; // cast
- String query =
- "insert into client values (" + client.getId() + ", '" + client.getName() +"', '" + client.getAddress() + "')";
- //String query = "begin insert_client(" + client.getId() + ", '" + client.getName() + "','" + client.getAddress() + "'); end";
- try {
- state.execute(query);
- success = true;
- } catch (SQLException e) {
- lastErrorMessage = "#N: " + e.getErrorCode() + "#Message: " + e.getMessage();
- disconnect();
- }
- disconnect();
- } else {
- }
- return success;
- }
- @Override
- public boolean delete(Object object) {
- boolean success = false;
- if (connect()) {
- this.client = (Client)object;
- String query = "delete from client c where c.id = " + client.getId();
- //String query = "begin delete_client(" + client.getId() + "); end";
- try {
- state.execute(query);
- success = true;
- } catch (SQLException e) {
- lastErrorMessage = "#N: " + e.getErrorCode() + "#Message: " + e.getMessage();
- disconnect();
- }
- disconnect();
- }
- return success;
- }
- @Override
- public boolean update(Object object) {
- boolean success = false;
- if (connect()) {
- this.client = (Client)object;
- String query =
- "update client c set c.id =" + client.getId() + ", c.name = '" + client.getName() + "', c.addr = '" + client.getAddress() + "' where c.id = " + client.getId();
- try {
- state.execute(query);
- success = true;
- } catch(SQLException e) {
- lastErrorMessage = "#N: " + e.getErrorCode() + "#Message: " + e.getMessage();
- disconnect();
- }
- disconnect();
- }
- return success;
- }
- @Override
- public boolean select(Object object) {
- boolean success = false;
- if (connect()) {
- this.client = (Client)object;
- String query =
- "select * from client c where c.id = " + client.getId();
- try {
- result = state.executeQuery(query);
- while (result.next()) {
- client.setId(result.getInt("id"));
- client.setName(result.getString("name"));
- client.setAddress(result.getString("addr"));
- }
- if ((client.getName() != null) && (client.getAddress() != null))
- success = true;
- } catch (SQLException e) {
- lastErrorMessage = "#N: " + e.getErrorCode() + "#Message: " + e.getMessage();
- disconnect();
- }
- disconnect();
- }
- return success;
- }
- // </editor-fold>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement