public void cleanup() { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = getConnection(); ps = conn.prepareStatement("SELECT COUNT(*) FROM FILES"); rs = ps.executeQuery(); dbCount = 0; if (rs.next()) { dbCount = rs.getInt(1); } rs.close(); ps.close(); PMS.get().getFrame().setStatusLine(Messages.getString("DLNAMediaDatabase.2") + " 0%"); int i = 0; int oldpercent = 0; if (dbCount > 0) { ps = conn.prepareStatement( "SELECT FILENAME, MODIFIED, ID FROM FILES", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); rs = ps.executeQuery(); while (rs.next()) { String filename = rs.getString("FILENAME"); long modified = rs.getTimestamp("MODIFIED").getTime(); File file = new File(filename); if (!file.exists() || file.lastModified() != modified) { rs.deleteRow(); } i++; int newpercent = i * 100 / dbCount; if (newpercent > oldpercent) { PMS.get() .getFrame() .setStatusLine(Messages.getString("DLNAMediaDatabase.2") + newpercent + "%"); oldpercent = newpercent; } } } } catch (SQLException se) { LOGGER.error(null, se); } finally { close(rs); close(ps); close(conn); } }
public ValoresAtualizaJob retornaNovosValores(Connection conn, JobLote job) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; ValoresAtualizaJob obj = null; String sql = " select sum(qtd_transf) qtd_transf, sum(qtd_sucata) qtd_sucata, sum(hr_tot) hr_tot from joblote\n" + " where job = ? and operacao = ? "; stmt = conn.prepareStatement(sql); stmt.setString(1, job.getJob().trim().replace(".", "")); stmt.setInt(2, job.getOperNum()); rs = stmt.executeQuery(); if (rs.next()) { obj = new ValoresAtualizaJob(); obj.setQtdTransf(rs.getDouble("qtd_transf")); obj.setQtdSucata(rs.getDouble("qtd_sucata")); obj.setHoraTotal(rs.getDouble("hr_tot")); } return obj; }
public JobIniciado retornaUltimoLote(Connection conn, String job, int operacao) throws SQLException { String sql = " select job, operacao, tripulacao,recurso, max(data_fim) \n" + "from joblote where job = ? and operacao = ? \n" + "group by job, operacao, tripulacao, recurso "; PreparedStatement stmt = null; ResultSet rs = null; JobIniciado iniciado = null; stmt = conn.prepareStatement(sql); stmt.setString(1, job.trim().replace(".", "")); stmt.setInt(2, operacao); rs = stmt.executeQuery(); if (rs.next()) { iniciado = new JobIniciado(); iniciado.setJob(rs.getString(1)); iniciado.setOperacao(rs.getInt(2)); iniciado.setTripulacao(rs.getDouble(3)); iniciado.setRecurso(rs.getString(4)); Timestamp data = rs.getTimestamp(5); iniciado.setData(Validacoes.getDataHoraString(data)); } return iniciado; }
public ArrayList<File> getFiles(String sql) { ArrayList<File> list = new ArrayList<File>(); Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; try { conn = getConnection(); ps = conn.prepareStatement( sql.toLowerCase().startsWith("select") ? sql : ("SELECT FILENAME, MODIFIED FROM FILES WHERE " + sql)); rs = ps.executeQuery(); while (rs.next()) { String filename = rs.getString("FILENAME"); long modified = rs.getTimestamp("MODIFIED").getTime(); File file = new File(filename); if (file.exists() && file.lastModified() == modified) { list.add(file); } } } catch (SQLException se) { LOGGER.error(null, se); return null; } finally { close(rs); close(ps); close(conn); } return list; }
public boolean validLogin(String username, String password) { boolean validUser = false; try { dbStm = dbCon.prepareStatement( "SELECT * FROM userInfo WHERE username = "******"\"" + username + "\"" + ";"); dbRs = dbStm.executeQuery(); while (dbRs.next()) { String un = ""; String pw = ""; un = dbRs.getString("username"); System.out.println(un + " " + username); pw = dbRs.getString("password"); System.out.println(pw + " " + password); if (((username.equals(un) == true) && ((password.equals(pw) == true)))) { validUser = true; System.out.println("Valid User"); } } } catch (Exception e) { e.printStackTrace(); } return validUser; }
public void actionPerformed(ActionEvent ae) { if (ae.getSource() == b1) { try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "123"); PreparedStatement ps = con.prepareStatement("select * from LoginForm where username=? and password=?"); String UserName = t1.getText(); String Password = jp1.getText(); ps.setString(1, UserName); ps.setString(2, Password); ResultSet rs = ps.executeQuery(); boolean flag = rs.next(); if (flag) { new Main(); f.setVisible(false); } else { JOptionPane.showMessageDialog(null, "Please Enter valid Name And Password"); } } catch (Exception e) { System.out.println("Error:" + e); } } else if (ae.getSource() == b2) { t1.setText(""); jp1.setText(""); } else if (ae.getSource() == b3) { f.setVisible(false); } }
private void LoginButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_LoginButtonActionPerformed // TODO add your handling code here: String sql = "select * from bruker where brukerNavn=? and brukerPassord=?"; try { int userType = accountType.getSelectedIndex(); pst = conn.prepareStatement(sql); pst.setString(1, UsrInput.getText()); pst.setString(2, PswdInput.getText()); rs = pst.executeQuery(); if (rs.next()) { // JOptionPane.showMessageDialog(null,"Username and password is correct"); close(); if (userType == 0) { MainPage m = new MainPage(); m.setVisible(true); } else { fMainPage fm = new fMainPage(); fm.setVisible(true); } } else { JOptionPane.showMessageDialog(null, "Username or password is incorrect"); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } // GEN-LAST:event_LoginButtonActionPerformed
/** * 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; } }
public static int retornaQtdTotal(Connection conn, JobProtheus job) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; int qtdTotal = 0; int qtdSucata = 0; String sqlVerQtd = "select job, sum(qtd_transf), sum(hr_tot), sum(qtd_sucata) from jobLote where job = ? and operacao = ? group by job"; stmt = conn.prepareStatement(sqlVerQtd); stmt.setString(1, job.getJob().trim()); stmt.setInt(2, job.getOperacao()); rs = stmt.executeQuery(); String qtdJob = ""; double totHora = 0; while (rs.next()) { qtdJob = rs.getString(1); // numero job qtdTotal = rs.getInt(2); // quantidade total totHora = rs.getInt(3); // hora total em minutos qtdSucata = rs.getInt(4); } return qtdTotal + qtdSucata; }
public ArrayList<String> getStrings(String sql) { ArrayList<String> list = new ArrayList<String>(); Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; try { conn = getConnection(); ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { String str = rs.getString(1); if (isBlank(str)) { if (!list.contains(NONAME)) { list.add(NONAME); } } else if (!list.contains(str)) { list.add(str); } } } catch (SQLException se) { LOGGER.error(null, se); return null; } finally { close(rs); close(ps); close(conn); } return list; }
private void fullAssociated() { boolean associated = true; String SQL = "Select * " + "from XX_VMR_REFERENCEMATRIX " + "where M_product IS NULL AND XX_VMR_PO_LINEREFPROV_ID=" + LineRefProv.get_ID(); try { PreparedStatement pstmt = DB.prepareStatement(SQL, null); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { associated = false; } rs.close(); pstmt.close(); } catch (Exception a) { log.log(Level.SEVERE, SQL, a); } if (associated == true) { String SQL10 = "UPDATE XX_VMR_PO_LineRefProv " + " SET XX_ReferenceIsAssociated='Y'" + " WHERE XX_VMR_PO_LineRefProv_ID=" + LineRefProv.getXX_VMR_PO_LineRefProv_ID(); DB.executeUpdate(null, SQL10); // LineRefProv.setXX_ReferenceIsAssociated(true); // LineRefProv.save(); int dialog = Env.getCtx().getContextAsInt("#Dialog_Associate_Aux"); if (dialog == 1) { ADialog.info(m_WindowNo, m_frame, "MustRefresh"); Env.getCtx().remove("#Dialog_Associate_Aux"); } } else { String SQL10 = "UPDATE XX_VMR_PO_LineRefProv " + " SET XX_ReferenceIsAssociated='N'" + " WHERE XX_VMR_PO_LineRefProv_ID=" + LineRefProv.getXX_VMR_PO_LineRefProv_ID(); DB.executeUpdate(null, SQL10); // LineRefProv.setXX_ReferenceIsAssociated(false); // LineRefProv.save(); } }
public static ResultSet collectRows1(String s) throws Exception { try { pps1.setString(1, s); rs = pps1.executeQuery(); } catch (Exception e13) { System.out.println("" + e13); } return rs; }
private void Update_table() { try { String sql = "SELECT * FROM trans where userid=? order by date asc "; pst = conn.prepareStatement(sql); pst.setString(1, branch.getText()); rs = pst.executeQuery(); jTable1.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
private void Update_table() { try { Connection conn = getConnect(); String sql = "SELECT * FROM LoggedInPeople"; PreparedStatement pst = conn.prepareStatement(sql); ResultSet rs = pst.executeQuery(); PeopleLoggedIn.setModel(DbUtils.resultSetToTableModel(rs)); closeConnect(); } catch (Exception e) { System.out.println(e); } }
public JobProtheus retornaJob(Connection conn, JobLote lote) throws SQLException { ResultSet rs = null; PreparedStatement stmt = null; JobProtheus job = null; String sql = "select job , B1_DESC, operacao , produto, "; sql += " dt_release, job_start_date , qtd_release, setor, qtd_transf "; sql += " from job left join " + DB_PROTHEUS.trim() + ".dbo.SB1000 SB1 "; sql += " on(produto collate SQL_Latin1_General_CP1_CI_AS = B1_COD) "; sql += " where job = ? and operacao = ? and SB1.D_E_L_E_T_ = '' "; sql += " order by dt_release, produto "; stmt = conn.prepareStatement(sql); stmt.setString(1, lote.getJob().trim()); stmt.setInt(2, lote.getOperNum()); rs = stmt.executeQuery(); while (rs.next()) { String nJob = rs.getString("job"); int operacao = rs.getInt("operacao"); String produto = rs.getString("produto"); Date dataEmissao = rs.getDate("dt_release"); Date dataPrevisaoInicio = rs.getDate("job_start_date"); String descricaoProduto = rs.getString("B1_DESC"); double quantidade = rs.getDouble("qtd_release"); String wc = rs.getString("setor"); String emissao = dataEmissao != null ? getDateToString(dataEmissao) : ""; String previsaoInicio = dataPrevisaoInicio != null ? getDateToString(dataPrevisaoInicio) : ""; job = new JobProtheus(); job.setStatus(""); job.setJob(nJob); job.setOperacao(operacao); job.setProduto(produto.trim()); job.setDataEmissao(emissao); job.setQuantidadeLiberada(quantidade); job.setDescricaoProduto(descricaoProduto); job.setCentroTrabalho(wc); double qtdTotal = retornaQtdTotal(conn, job); // calcula o total transferido para o job job.setQuantidadeCompleta(qtdTotal); job.setDataPrivisaoInicio(previsaoInicio); job.setQuantidadeFaltando(quantidade - qtdTotal); // seta o valor qtd faltando } return job; // retorna lista de jobs }
private void Update_Table() { try { String sql = "select * from Bank_001"; PreparedStatement pst = conn.prepareStatement(sql); ResultSet rs = pst.executeQuery(); table.setModel(DbUtils.resultSetToTableModel(rs)); conn.close(); } catch (Exception e) { e.printStackTrace(); } }
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; }
public boolean verificaSeSetorTemLinhaTempo(Connection conn, String setor) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; String sql = "select linha_tempo from setor where setor = ? and linha_tempo = ? "; stmt = conn.prepareStatement(sql); stmt.setString(1, setor.trim()); stmt.setBoolean(2, true); rs = stmt.executeQuery(); if (rs.next()) { return true; } else { return false; } }
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; }
public boolean verificarSeJobEstaTabelaIniciado(Connection conn, String job, int operacao) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; String update = "select ativo from jobsiniciados where job = ? and operacao = ?"; stmt = conn.prepareStatement(update); stmt.setString(1, job.trim().replace(".", "")); stmt.setInt(2, operacao); rs = stmt.executeQuery(); if (rs.next()) { return true; } return false; }
private void viewalllllActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_viewalllllActionPerformed try { String sql3 = "SELECT date,SUM(cost) AS TotalAmountReceived FROM trans WHERE branch=? GROUP BY date order by date asc"; pst = conn.prepareStatement(sql3); pst.setString(1, branch.getText()); rs = pst.executeQuery(); jTable1.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } // GEN-LAST:event_viewalllllActionPerformed
public void check_Password() { String password = "******"; String sql = "Select * from user where user_id = '" + dataUser + "'"; boolean password_valid = false; try { PreparedStatement stat = konek.prepareStatement(sql); ResultSet rset = stat.executeQuery(); while (rset.next()) { password = rset.getString("psw"); if (password.equalsIgnoreCase(dataPassword)) { password_valid = true; status_Proses(true, "Sukses!!!Password Valid...", 20); } } if (password_valid == false) { status_Proses(false, "Gagal!!!Password yang Anda Masukan Salah...", 20); } } catch (SQLException se) { } }
public void check_User() { String user = ""; String sql = "Select * from user"; boolean user_valid = false; try { PreparedStatement stat = konek.prepareStatement(sql); ResultSet rset = stat.executeQuery(); while (rset.next()) { user = rset.getString("username"); if (user.equalsIgnoreCase(dataUser)) { user_valid = true; status_Proses(true, "Sukses!!!User Name Valid...", 20); } } if (user_valid == false) { status_Proses(false, "Gagal!!!User yang Anda Masukan Salah...", 20); } } catch (SQLException se) { } }
private void fill_combo() { try { String sql = "select distinct townname from towntrends.trends "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { String name = rs.getString("townname"); jComboBox1.addItem(name); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex); } finally { try { pst.close(); rs.close(); } catch (Exception ex) { } } }
private void viewallamountActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_viewallamountActionPerformed Object item = date1.getText(); Object item1 = date2.getText(); String sql = "select date,SUM(cost) AS TotalAmountReceived from trans where branch=? and date between '" + item + "' and '" + item1 + "'GROUP BY date order by date"; try { pst = conn.prepareStatement(sql); pst.setString(1, branch.getText()); rs = pst.executeQuery(); jTable1.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } // GEN-LAST:event_viewallamountActionPerformed
/** * verifica si hay productos asociados * * @param table table */ private boolean verify() { String sql = "SELECT XX_VMR_ReferenceMatrix_ID " + "FROM XX_VMR_ReferenceMatrix " + "WHERE XX_VMR_PO_LINEREFPROV_ID=" + (Integer) LineRefProv.getXX_VMR_PO_LineRefProv_ID(); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); rs = pstmt.executeQuery(); while (rs.next()) { associatedReference_ID = rs.getInt("XX_VMR_ReferenceMatrix_ID"); rs.close(); pstmt.close(); return true; } } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } finally { try { rs.close(); } catch (SQLException e1) { e1.printStackTrace(); } try { pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } return false; } // tableLoad
private boolean isInMatrix() { String SQL = "Select * " + "from XX_VMR_REFERENCEMATRIX " + "where XX_VMR_PO_LINEREFPROV_ID=" + LineRefProv.get_ID(); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(SQL, null); rs = pstmt.executeQuery(); while (rs.next()) { return true; } } catch (Exception a) { log.log(Level.SEVERE, SQL, a); } finally { try { rs.close(); } catch (SQLException e1) { e1.printStackTrace(); } try { pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } return false; }
private void selectData() { setModelTabel(); // JOptionPane.showMessageDialog(null, "sfsfs"); try { PreparedStatement stat = conn.prepareStatement( "" + "SELECT HR_EMPLOYEE.empno, HR_EMPLOYEE.name, HR_EMPLOYEE.full_name, HR_PROMOTION.pclass, HR_EMPLOYEE.emp_status, " + "fn_code_name(HR_EMPLOYEE.company, 'CA02', HR_EMPLOYEE.plant) as plant, " + "fn_dept_name(HR_EMPLOYEE.company,HR_EMPLOYEE.plant,HR_PROMOTION.dept,'99999999') as dept, HR_PROMOTION.grade, " + "fn_code_name(HR_EMPLOYEE.company,'PC03',HR_PROMOTION.position) as position, fn_code_name(HR_EMPLOYEE.company,'PC02',HR_PROMOTION.job) as job " + "FROM public.HR_EMPLOYEE LEFT OUTER JOIN public.HR_PROMOTION ON public.HR_EMPLOYEE.empno = public.HR_PROMOTION.empno " + "WHERE HR_EMPLOYEE.company = ? " + "AND ( (HR_EMPLOYEE.empno LIKE '%' || ? || '%') " + "OR (HR_EMPLOYEE.name LIKE '%' || ? || '%') " + "OR (HR_EMPLOYEE.full_name LIKE '%' || ? || '%') ) " + "ORDER BY HR_EMPLOYEE.name, HR_EMPLOYEE.empno"); stat.setString(1, GlobVar.gs_company); stat.setString(2, jTextField1.getText()); stat.setString(3, jTextField1.getText()); stat.setString(4, jTextField1.getText()); ResultSet rs = stat.executeQuery(); DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); while (rs.next()) { dtm.addRow( new Object[] { rs.getString("empno"), rs.getString("name"), rs.getString("full_name"), rs.getString("dept"), rs.getString("emp_status") }); } } catch (Exception e) { e.printStackTrace(); } }
public boolean isDataExists(String name, long modified) { boolean found = false; Connection conn = null; ResultSet rs = null; PreparedStatement stmt = null; try { conn = getConnection(); stmt = conn.prepareStatement("SELECT * FROM FILES WHERE FILENAME = ? AND MODIFIED = ?"); stmt.setString(1, name); stmt.setTimestamp(2, new Timestamp(modified)); rs = stmt.executeQuery(); while (rs.next()) { found = true; } } catch (SQLException se) { LOGGER.error(null, se); return false; } finally { close(rs); close(stmt); close(conn); } return found; }
public static boolean psearch(int n) throws Exception { pps.setInt(1, n); rs = pps.executeQuery(); return rs.next(); }