예제 #1
1
      public void actionPerformed(ActionEvent ev) {
        try {
          // stok
          String query = "DELETE FROM stok_produk WHERE id_produk=" + idProduk;
          int hasil1 = stm.executeUpdate(query);

          // pemasukkan
          query = "DELETE FROM pemasukan WHERE id_produk=" + idProduk;
          int hasil2 = stm.executeUpdate(query);

          // pengeluaran
          query = "DELETE FROM pengeluaran WHERE id_produk=" + idProduk;
          int hasil3 = stm.executeUpdate(query);

          // produk
          query = "DELETE FROM produk WHERE id_produk=" + idProduk;
          int hasil4 = stm.executeUpdate(query);

          if (hasil1 == 1 || hasil2 == 1 || hasil3 == 1 && hasil4 == 1) {
            setDataTabel();
            JOptionPane.showMessageDialog(null, "berhasil hapus");
          } else {
            JOptionPane.showMessageDialog(null, "gagal");
          }
        } catch (SQLException SQLerr) {
          SQLerr.printStackTrace();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
예제 #2
0
 public static void closeConnect() {
   try {
     con.close();
   } catch (SQLException e) {
     MessageBox.infoBox(e.toString(), "Error in closeConnect");
   }
 }
예제 #3
0
  /**
   * _more_
   *
   * @return _more_
   */
  public Connection getConnection() {
    if (connection != null) {
      return connection;
    }
    String url = getFilename();
    if ((dataSource.getUserName() == null) || (dataSource.getUserName().trim().length() == 0)) {
      if (url.indexOf("?") >= 0) {
        int idx = url.indexOf("?");
        List<String> args =
            (List<String>) StringUtil.split(url.substring(idx + 1), "&", true, true);
        url = url.substring(0, idx);
        for (String tok : args) {
          List<String> subtoks = (List<String>) StringUtil.split(tok, "=", true, true);
          if (subtoks.size() != 2) {
            continue;
          }
          String name = subtoks.get(0);
          String value = subtoks.get(1);
          if (name.equals("user")) {
            dataSource.setUserName(value);
          } else if (name.equals("password")) {
            dataSource.setPassword(value);
          }
        }
      }
    }

    int cnt = 0;
    while (true) {
      String userName = dataSource.getUserName();
      String password = dataSource.getPassword();
      if (userName == null) {
        userName = "";
      }
      if (password == null) {
        password = "";
      }
      try {
        connection = DriverManager.getConnection(url, userName, password);
        return connection;
      } catch (SQLException sqe) {
        if ((sqe.toString().indexOf("role \"" + userName + "\" does not exist") >= 0)
            || (sqe.toString().indexOf("user name specified") >= 0)) {
          String label;
          if (cnt == 0) {
            label =
                "<html>The database requires a login.<br>Please enter a user name and password:</html>";
          } else {
            label = "<html>Incorrect username/password. Please try again.</html>";
          }
          if (!dataSource.showPasswordDialog("Database Login", label)) {
            return null;
          }
          cnt++;
          continue;
        }
        throw new BadDataException("Unable to connect to database", sqe);
      }
    }
  }
  public void display(ResultSet rs) {
    try {
      boolean recordNumber = rs.next();
      if (recordNumber) {
        payNo = rs.getString(1);
        pasNo = rs.getString(2);
        pasName = rs.getString(3);
        mode = rs.getString(4);
        dt = rs.getString(5);
        amount = rs.getString(6);
        rev = rs.getString(7);

        text1.setText(payNo);
        combo1.setSelectedItem(pasNo);
        combo2.setSelectedItem(pasName);
        combo4.setSelectedItem(mode);
        p_date.setText(dt);
        combo8.setSelectedItem(amount);
        combo3.setSelectedItem(rev);

      } else {
        JOptionPane.showMessageDialog(
            null, "Record Not found", "ERROR", JOptionPane.DEFAULT_OPTION);
      }
    } catch (SQLException sqlex) {
      sqlex.printStackTrace();
    }
  }
 public synchronized void updateThumbnail(
     String name, long modified, int type, DLNAMediaInfo media) {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = getConnection();
     ps = conn.prepareStatement("UPDATE FILES SET THUMB = ? WHERE FILENAME = ? AND MODIFIED = ?");
     ps.setString(2, name);
     ps.setTimestamp(3, new Timestamp(modified));
     if (media != null) {
       ps.setBytes(1, media.getThumb());
     } else {
       ps.setNull(1, Types.BINARY);
     }
     ps.executeUpdate();
   } catch (SQLException se) {
     if (se.getErrorCode() == 23001) {
       LOGGER.debug(
           "Duplicate key while inserting this entry: "
               + name
               + " into the database: "
               + se.getMessage());
     } else {
       LOGGER.error(null, se);
     }
   } finally {
     close(ps);
     close(conn);
   }
 }
예제 #6
0
 public void excluir(Oriundo oriundo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   String sqlExcluir = "DELETE FROM oriundo WHERE codigo=?";
   try {
     ps = con.prepareStatement(sqlExcluir);
     ps.setInt(1, oriundo.getCodigo());
     ps.executeUpdate();
     JOptionPane.showMessageDialog(
         null, "Ecluido Com Sucesso: ", "Mensagem do Sistema - Excluir", 1);
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Excluir", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
 }
예제 #7
0
  @Override
  public void actionPerformed(ActionEvent axnEve) {
    Object obj = axnEve.getSource();
    if (obj == replyBut) {
      try {
        if (Home.composeDial != null && Home.composeDial.isShowing()) {

        } else {
          Home.composeDial =
              new ComposeMailDialog(
                  msgID, workingSet.getString("mail_addresses"), workingSet.getString("subject"));
        }
      } catch (SQLException sqlExc) {
        sqlExc.printStackTrace();
      }
    } else if (obj == forwardBut) {
      try {
        if (Home.composeDial != null && Home.composeDial.isShowing()) {

        } else {
          Home.composeDial =
              new ComposeMailDialog(
                  msgID,
                  workingSet.getString("subject") + "\n\n" + workingSet.getString("content"));
        }
      } catch (SQLException sqlExc) {
        sqlExc.printStackTrace();
      }
    }
  }
예제 #8
0
  /**
   * metoda pobierajaca wszystkie rekordy z BD1.
   *
   * @return
   */
  public ArrayList<StudentFirst> getAllStudentFromDBfirst() {
    logger.info("getAllContactFromDB");
    ResultSet result = null;
    ArrayList<StudentFirst> students = new ArrayList<>();
    try {
      prepStmt = conn.prepareStatement("SELECT * FROM student1");
      result = prepStmt.executeQuery();
      int id, index;
      String name, surname, university, faculty, field;

      for (int i = 0; result.next(); i++) {
        id = result.getInt("stud1_id");
        index = result.getInt("stud1_index");
        name = result.getString("stud1_name");
        surname = result.getString("stud1_lastname");
        university = result.getString("stud1_university");
        faculty = result.getString("stud1_faculty");
        field = result.getString("stud1_field");
        students.add(new StudentFirst(id, index, name, surname, university, faculty, field));
        logger.info(students.get(i).toString());
      }

      if (students.size() == 0) {
        logger.info("Pusta BD?");
      }
      return students;
    } catch (SQLException e1) {
      JOptionPane.showMessageDialog(null, e1);
      e1.printStackTrace();
      return null;
    }
  }
예제 #9
0
  public void actionPerformed(java.awt.event.ActionEvent evt) {
    String sql1 =
        "select a.* FROM ANTENA a WHERE a.ID_antena='"
            + (newJPanel.jList1.getSelectedIndex() + 1)
            + "' ";
    String pom = "";
    System.out.println(sql1);
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection conn;
      try {
        conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", user, password);

        Statement stmt1 = conn.createStatement();
        ResultSet rs1 = stmt1.executeQuery(sql1);
        while (rs1.next()) {
          NewJPanel.jTextField1.setText(rs1.getString("ID_antena"));
          NewJPanel.jTextField2.setText(rs1.getString("Producent"));
          NewJPanel.jTextField3.setText(rs1.getString("Numer_identyfikacyjny"));
          NewJPanel.jTextField4.setText(rs1.getString("Czestotliwosc"));
          NewJPanel.jTextField5.setText(rs1.getString("Polaryzacja"));
          NewJPanel.jTextField6.setText(rs1.getString("Moc"));
          NewJPanel.jTextField7.setText(rs1.getString("Rodzaj"));
        }
      } catch (SQLException e1) {
        System.out.println("tutaj 1");
        e1.printStackTrace();
      }
    } catch (ClassNotFoundException e1) {
      System.out.println("tutaj 2");
      e1.printStackTrace();
    }
  }
예제 #10
0
  public ExptLocatorTree(Genome g) {
    super();
    try {
      java.sql.Connection c = DatabaseFactory.getConnection(ExptLocator.dbRole);
      int species = g.getSpeciesDBID();
      int genome = g.getDBID();

      Statement s = c.createStatement();
      ResultSet rs = null;

      rs =
          s.executeQuery(
              "select e.name, e.version from experiment e, exptToGenome eg where e.active=1 and "
                  + "e.id=eg.experiment and eg.genome="
                  + genome);
      while (rs.next()) {
        String name = rs.getString(1);
        String version = rs.getString(2);
        ChipChipLocator loc = new ChipChipLocator(g, name, version);
        this.addElement(loc.getTreeAddr(), loc);
      }
      rs.close();

      rs =
          s.executeQuery(
              "select ra.name, ra.version from rosettaanalysis ra, rosettaToGenome rg where "
                  + "ra.id = rg.analysis and ra.active=1 and rg.genome="
                  + genome);
      while (rs.next()) {
        String name = rs.getString(1);
        String version = rs.getString(2);
        MSPLocator msp = new MSPLocator(g, name, version);
        this.addElement(msp.getTreeAddr(), msp);
      }
      rs.close();

      rs =
          s.executeQuery(
              "select ra.name, ra.version from bayesanalysis ra, bayesToGenome rg where "
                  + "ra.id = rg.analysis and ra.active=1 and rg.genome="
                  + genome);
      while (rs.next()) {
        String name2 = rs.getString(1);
        String version2 = rs.getString(2);
        ExptLocator loc2 = new BayesLocator(g, name2, version2);
        addElement(loc2.getTreeAddr(), loc2);
      }
      rs.close();
      s.close();

      DatabaseFactory.freeConnection(c);
    } catch (SQLException se) {
      se.printStackTrace(System.err);
      throw new RuntimeException(se);
    } catch (UnknownRoleException e) {
      e.printStackTrace();
    }
  }
예제 #11
0
 private void submitButtonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_submitButtonActionPerformed
   // TODO add your handling code here:
   Connection con = FrameLogin.getConnect();
   String SQLInsert =
       "INSERT INTO `2761DB`.`Persons` (`FirstName`, `LastName`, `CellPhoneNo`, `HomePhoneNo`, "
           + "`SchoolId`, `Graduation Year`, `Gender`) VALUES ('"
           + firstName.getText()
           + "', '"
           + lastName.getText()
           + "', '"
           + cellPhone.getText()
           + "', '"
           + homePhone.getText()
           + "', '"
           + studentId.getText()
           + "', '"
           + gradYear.getText()
           + "', '"
           + (String) (gender.getSelectedItem())
           + "');";
   String SQLUpdate =
       "UPDATE `2761DB`.`Persons` SET `FirstName` = '"
           + firstName.getText()
           + "', `LastName` = '"
           + lastName.getText()
           + "', `CellPhoneNo` = ' "
           + cellPhone.getText()
           + "', `HomePhoneNo` = '"
           + homePhone.getText()
           + "', `Graduation Year` = '"
           + gradYear.getText()
           + "', `Gender` = '"
           + (String) (gender.getSelectedItem())
           + "' WHERE `PersonId` = '"
           + Id
           + "';";
   // UPDATE `2761DB`.`Persons` SET `FirstName`='Robbie', `LastName`='Tacescu', `CellPhoneNo`='',
   // `HomePhoneNo`='559300', `SchoolId`='15648916', `Graduation Year`='6545', `Gender`='males'
   // WHERE
   // `PersonId`='42';
   try {
     if (isEdit) {
       Statement stmt = con.createStatement();
       // System.out.println(SQLUpdate);
       stmt.executeUpdate(SQLUpdate);
     } else {
       Statement stmt = con.createStatement();
       // System.out.println(SQLInsert);
       stmt.executeUpdate(SQLInsert);
     }
   } catch (SQLException err) {
     MessageBox.infoBox(err.toString(), "Error in AddUserForm submitButton");
   }
   FrameLogin.closeConnect();
   this.dispose();
 } // GEN-LAST:event_submitButtonActionPerformed
 private void close(ResultSet rs) {
   try {
     if (rs != null) {
       rs.close();
     }
   } catch (SQLException e) {
     LOGGER.error("error during closing:" + e.getMessage(), e);
   }
 }
 private void close(Statement ps) {
   try {
     if (ps != null) {
       ps.close();
     }
   } catch (SQLException e) {
     LOGGER.error("error during closing:" + e.getMessage(), e);
   }
 }
 private void close(Connection conn) {
   try {
     if (conn != null) {
       conn.close();
     }
   } catch (SQLException e) {
     LOGGER.error("error during closing:" + e.getMessage(), e);
   }
 }
예제 #15
0
 private void passwordTextBoxKeyPressed(
     java.awt.event.KeyEvent evt) { // GEN-FIRST:event_passwordTextBoxKeyPressed
   // TODO add your handling code here:
   int key = evt.getKeyCode();
   if (key == KeyEvent.VK_ENTER) {
     boolean verify = false;
     String user = usernameTextBox.getText();
     String passwd = passwordTextBox.getText();
     if (user.equals("") || passwd.equals("")) {
       JOptionPane.showMessageDialog(
           AdminLogin.this, "Sorry! You must enter a Username and Password to login ");
       usernameTextBox.requestFocus();
     } else {
       Connection con = getConnection();
       try {
         ResultSet rows;
         Statement s =
             con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
         String select = "Select * from admin;";
         rows = s.executeQuery(select);
         while (rows.next()) {
           String username = rows.getString("Username");
           String password = rows.getString("Password");
           if (user.equals(username) && passwd.equals(password)) {
             verify = true;
             this.dispose();
             //                       btn.btnEnabled();
             break;
           }
         }
         if (verify == false) {
           verify = false;
           JOptionPane.showMessageDialog(
               AdminLogin.this, "Access Denied! Invalid Username or Password");
           usernameTextBox.setText("");
           passwordTextBox.setText("");
           usernameTextBox.requestFocus();
         }
       } catch (SQLException e) {
         System.out.println(e.getMessage());
       }
       if (verify == false) {
         JOptionPane.showMessageDialog(
             AdminLogin.this, "Access Denied!  Invalid Username or Password");
         usernameTextBox.setText("");
         passwordTextBox.setText("");
         usernameTextBox.requestFocus();
       } // TODO add your handling code here:
     }
   }
   if (key == KeyEvent.VK_UP) {
     usernameTextBox.grabFocus();
   }
   if (key == KeyEvent.VK_KP_UP) {
     usernameTextBox.grabFocus();
   }
 } // GEN-LAST:event_passwordTextBoxKeyPressed
예제 #16
0
 public void run() {
   m_nTrans = 0;
   m_nTrans1Sec = 0;
   m_nTrans2Sec = 0;
   m_nTimeSum = 0;
   if (m_nNumRuns <= 0) return;
   Statement stmt = null;
   try {
     stmt = m_conn.createStatement();
     ResultSet set;
     // get branch count
     log("select max(branch) from " + m_Driver.getBranchName() + "\n", 2);
     set = stmt.executeQuery("select max(branch) from " + m_Driver.getBranchName());
     if (set != null && set.next()) {
       m_nMaxBranch = set.getInt(1);
       set.close();
     }
     // get teller count
     log("select max(teller) from " + m_Driver.getTellerName() + "\n", 2);
     set = stmt.executeQuery("select max(teller) from " + m_Driver.getTellerName());
     if (set != null && set.next()) {
       m_nMaxTeller = set.getInt(1);
       set.close();
     }
     // get account count
     log("select max(account) from " + m_Driver.getAccountName() + "\n", 2);
     set = stmt.executeQuery("select max(account) from " + m_Driver.getAccountName());
     if (set != null && set.next()) {
       m_nMaxAccount = set.getInt(1);
       set.close();
     }
   } catch (SQLException e) {
     log("Error getting table limits : " + e.getMessage() + "\n", 0);
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException e) {
       }
     stmt = null;
   }
   //		System.out.println("Thread : " + getName() + " Branch :" + m_nMaxBranch + " Teller : " +
   // m_nMaxTeller + " Account : " + m_nMaxAccount);
   if (m_bRunText) runTextTest();
   if (m_bRunPrepared) runPrepareTest();
   if (m_bRunSProc) runProcTest();
   if (m_bCloseConnection) {
     try {
       m_conn.close();
       log("Thread connection closed", 2);
     } catch (SQLException e) {
     }
   }
   if (m_log != null) m_log.taskDone();
 }
예제 #17
0
 private void prosesEdit(String query) {
   try {
     int hasil = stm.executeUpdate(query);
     if (hasil == 1) {
       setDataTabel();
       JOptionPane.showMessageDialog(null, "edit berhasil");
     } else {
       JOptionPane.showMessageDialog(null, "gagal");
     }
   } catch (SQLException SQLerr) {
     SQLerr.printStackTrace();
   }
 }
예제 #18
0
 private void logIn(int personId) {
   Connection con = getConnect();
   try {
     // MessageBox.infoBox("You have successfully logged in", "Login");
     // INSERT INTO LogInOut (PersonId, TimeIn) VALUES (1, NOW())
     String SQLLogin = "******" + personId + ", NOW())";
     Statement stmtLogin = con.createStatement();
     stmtLogin.executeUpdate(SQLLogin);
     Update_table();
   } catch (SQLException err) {
     MessageBox.infoBox(err.toString(), "Error");
   }
   closeConnect();
 }
예제 #19
0
 public List<Oriundo> listar() throws SQLException {
   List<Oriundo> resultado = new ArrayList<Oriundo>();
   conexao propCon = new conexao();
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           propCon.config.getString("usuario"),
           propCon.config.getString("senha"));
   PreparedStatement ps = null;
   ResultSet rs = null;
   String sqlListar = "SELECT * FROM oriundo Order by codigo DESC";
   Oriundo oriundo;
   try {
     ps = con.prepareStatement(sqlListar);
     rs = ps.executeQuery();
     // if(rs==null){
     // return null;
     // }
     while (rs.next()) {
       oriundo = new Oriundo();
       oriundo.setCodigo(rs.getInt("codigo"));
       oriundo.setDescricao(rs.getString("descricao"));
       oriundo.setData_cadastro(rs.getDate("data_cadastro"));
       oriundo.setDia_fechamento(rs.getInt("dia_fechamento"));
       oriundo.setDia_pag(rs.getInt("dia_pag"));
       resultado.add(oriundo);
     }
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Localizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
   return resultado;
 }
예제 #20
0
 public static Connection getConnect() {
   try {
     /*if (!getConnect) {
     if (!con.isValid(1)) {*/
     String host = "jdbc:mysql://localhost:3306/2761DB";
     String uname = "root";
     String upassword = "******";
     con = DriverManager.getConnection(host, uname, upassword);
     getConnect = true;
     /*}
     }*/
   } catch (SQLException err) {
     System.out.println(err.getMessage());
   }
   return con;
 }
  private void insertTestData() {

    try {
      DatabaseManagerCommon.createTestTables(sStatement);
      refreshTree();
      txtCommand.setText(DatabaseManagerCommon.createTestData(sStatement));
      refreshTree();

      for (int i = 0; i < DatabaseManagerCommon.testDataSql.length; i++) {
        addToRecent(DatabaseManagerCommon.testDataSql[i]);
      }

      execute();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
예제 #22
0
 public void setJenis() {
   dataJenis = new ArrayList<Jenis>();
   try {
     String qry = "SELECT * from jenis";
     ResultSet rs = stm.executeQuery(qry);
     while (rs.next()) {
       Jenis j = new Jenis();
       j.setIdJenis(rs.getInt("id_jenis"));
       j.setNamaJenis(rs.getString("nama_jenis"));
       dataJenis.add(j);
     }
   } catch (SQLException SQLerr) {
     SQLerr.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #23
0
  public static void updateDoljnost() {
    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      comboBox_doljnost.removeAllItems();
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
      }

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(null, ee.getMessage());
    }
  }
예제 #24
0
  public static void updateKvalification() {
    try {

      DBClass db2 = new DBClass();
      ArrayList<Kvalification> k = db2.kvalificationFromDB();
      comboBox_kvalification.removeAllItems();
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(null, ee.getMessage());
    }
  }
예제 #25
0
 public Oriundo localizar(Integer codigo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   ResultSet rs = null;
   String sqlLocalizar = "SELECT * FROM oriundo WHERE codigo=?";
   Oriundo oriundo = new Oriundo();
   try {
     ps = con.prepareStatement(sqlLocalizar);
     ps.setInt(1, codigo);
     rs = ps.executeQuery();
     // if(!rs.next()){
     // return null;
     // }
     oriundo.setCodigo(rs.getInt("codigo"));
     oriundo.setDescricao(rs.getString("descricao"));
     oriundo.setData_cadastro(rs.getDate("data_cadastro"));
     oriundo.setDia_fechamento(rs.getInt("dia_fechamento"));
     oriundo.setDia_pag(rs.getInt("dia_pag"));
     return oriundo;
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Localizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
   return oriundo;
 }
예제 #26
0
 private void logOut(int personId) {
   Connection con = getConnect();
   try {
     // MessageBox.infoBox("You have successfully logged out", "Logout");
     // UPDATE LogInOut SET TimeOut = NOW() WHERE PersonId = 1 AND TimeOut IS NULL
     String SQLLogin =
         "******"
             + personId
             + " AND TimeOut IS NULL";
     Statement stmtLogin = con.createStatement();
     stmtLogin.executeUpdate(SQLLogin);
     Update_table();
   } catch (SQLException err) {
     System.out.println(err);
     MessageBox.infoBox(err.toString(), "Error");
   }
   closeConnect();
 }
예제 #27
0
  // Вид формы при изменении сотрудника
  public void sotrDiaUpdate(Sotrudnik s) {
    label_id_hidden.setText(Integer.toString(s.getId_sotrudnika()));
    textField_familiya.setText(s.getFamiliya());
    textField_imya.setText(s.getImya());
    textField_otchestvo.setText(s.getOtchestvo());
    textField_phone.setText(s.getPhone());
    textField_date.setText(s.getData_priema().toString());
    comboBox_doljnost.removeAllItems();
    comboBox_kvalification.removeAllItems();

    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      DBClass db2 = new DBClass();
      Doljnost dd = db2.doljnostFromDB(s);
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
        Doljnost ddd = (Doljnost) comboBox_doljnost.getItemAt(i);
        if (dd.getNazvanie_doljnosti().equals(ddd.getNazvanie_doljnosti())) dd = ddd;
      }
      comboBox_doljnost.setSelectedItem(dd);

      DBClass db3 = new DBClass();
      ArrayList<Kvalification> k = db3.kvalificationFromDB();
      DBClass db4 = new DBClass();
      Kvalification kk = db4.kvalificationFromDB(s);
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
        Kvalification kkk = (Kvalification) comboBox_kvalification.getItemAt(i);
        if (kk.getNazvanie_kvalification().equals(kkk.getNazvanie_kvalification())) kk = kkk;
      }

      comboBox_kvalification.setSelectedItem(kk);

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(panelException, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(panelException, ee.getMessage());
    }
  }
예제 #28
0
  // public method that checks for existance of children
  public boolean HasChildren(String tsn) {

    String temp = "SELECT tsn from Tree where parent_tsn='" + tsn + "'";
    if (lrank.compareTo("0") != 0 && lrank.compareTo("7") != 0)
      temp = temp + " AND rank_id<=" + lrank;
    System.out.println(temp);
    int numberOfRows = 0;
    boolean flag = false;
    try {
      result = statement.executeQuery(temp);
      metadata = result.getMetaData();
      if (result.last()) numberOfRows = result.getRow();
      result.first();
      if (numberOfRows > 0 && metadata.getColumnCount() > 0) flag = true;
    } catch (SQLException sql) {
      sql.printStackTrace();
      System.exit(1);
    }
    return flag;
  } // end of method HasChildren
예제 #29
0
 private static Connection getConnection() {
   Connection con = null;
   try {
     Class.forName("com.mysql.jdbc.Driver");
     String url = "jdbc:mysql://localhost:3306/SMS";
     String user = "******";
     String pw = "";
     con = DriverManager.getConnection(url, user, pw);
   } catch (ClassNotFoundException e) {
     System.out.println("Unable to locate class");
     System.out.println(e.getMessage());
     JOptionPane.showMessageDialog(null, " Database not connected");
     // System.exit(0);
   } catch (SQLException e) {
     System.out.println(e.getMessage());
     JOptionPane.showMessageDialog(null, " Database not connected");
     // System.exit(0);
   }
   return con;
 }
예제 #30
0
  // Вид формы при добавлении нового сотрудника
  public void sotrDiaInsert() {
    label_id_hidden.setText("Новый сотрудник");
    textField_familiya.setText("");
    textField_imya.setText("");
    textField_otchestvo.setText("");
    textField_phone.setText("");
    comboBox_doljnost.removeAllItems();
    comboBox_kvalification.removeAllItems();

    Calendar calend = Calendar.getInstance();
    if (calend.get(Calendar.MONTH) <= 9) {
      textField_date.setText(
          String.valueOf(
              (calend.get(Calendar.YEAR) + "-" + ("0" + (1 + calend.get(Calendar.MONTH))) + "-")
                  + (calend.get(Calendar.DATE))));
    } else
      textField_date.setText(
          String.valueOf(
              ((calend.get(Calendar.YEAR)) + "-" + (1 + calend.get(Calendar.MONTH)) + "-")
                  + (calend.get(Calendar.DATE))));
    textField_date.setEnabled(false);

    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
      }
      DBClass db2 = new DBClass();
      ArrayList<Kvalification> k = db2.kvalificationFromDB();
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(panelException, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(panelException, ee.getMessage());
    }
  }