private boolean AidedIn(SaoWorker w) { BatSQL bSQL = new BatSQL(); boolean success = false; String id = w.getUserID(); String q = "select * from aidedin where USERID='" + id + "'"; ResultSet rs = bSQL.query(q); try { boolean more = rs.next(); if (more) { success = true; } } //end of try catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.exit(0); } //end catching other Exceptions bSQL.disconnect(); return success; } //end of AidedIn?
/** Method declaration Adjust this method for large strings...ie multi megabtypes. */ void execute() { String sCmd = null; if (4096 <= ifHuge.length()) { sCmd = ifHuge; } else { sCmd = txtCommand.getText(); } if (sCmd.startsWith("-->>>TEST<<<--")) { testPerformance(); return; } String g[] = new String[1]; lTime = System.currentTimeMillis(); try { sStatement.execute(sCmd); lTime = System.currentTimeMillis() - lTime; int r = sStatement.getUpdateCount(); if (r == -1) { formatResultSet(sStatement.getResultSet()); } else { g[0] = "update count"; gResult.setHead(g); g[0] = String.valueOf(r); gResult.addRow(g); } addToRecent(txtCommand.getText()); } catch (SQLException e) { lTime = System.currentTimeMillis() - lTime; g[0] = "SQL Error"; gResult.setHead(g); String s = e.getMessage(); s += " / Error Code: " + e.getErrorCode(); s += " / State: " + e.getSQLState(); g[0] = s; gResult.addRow(g); } updateResult(); System.gc(); }
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
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; }
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()); } }
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()); } }
// Вид формы при изменении сотрудника 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()); } }
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; }
// Вид формы при добавлении нового сотрудника 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()); } }
/** * Finds out if an aide is covering for another aide * and makes an entry to the AIDELOG to note that * coverage has ended. * * @param The SaoWorker who might be covering */ public void Covering(final SaoWorker w) { BatSQL bSQL = new BatSQL(); String qc = "select * from AIDEDIN where USERID='" + w.getUserID() + "'"; ResultSet rs = bSQL.query(qc); String cid = new String(); try { rs.next(); cid = rs.getString(2); } catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); System.out.println("Covering"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.out.println("Covering"); System.exit(0); } //end catching other Exceptions if (!cid.equals("No")) //then covering { String uc = "insert into AIDELOG values ('C', '" + cid + "', \"" + bd.getDate() + "\", " + bd.getStringHours() + bd.getStringMinutes() + ", 'O')"; bSQL.update(uc); } bSQL.disconnect(); } //end of Covering
/** Method declaration */ private void refreshTree() { tTree.removeAll(); try { int color_table = Color.yellow.getRGB(); int color_column = Color.orange.getRGB(); int color_index = Color.red.getRGB(); tTree.addRow("", dMeta.getURL(), "-", 0); String usertables[] = {"TABLE"}; ResultSet result = dMeta.getTables(null, null, null, usertables); Vector tables = new Vector(); // sqlbob@users Added remarks. Vector remarks = new Vector(); while (result.next()) { tables.addElement(result.getString(3)); remarks.addElement(result.getString(5)); } result.close(); for (int i = 0; i < tables.size(); i++) { String name = (String) tables.elementAt(i); String key = "tab-" + name + "-"; tTree.addRow(key, name, "+", color_table); // sqlbob@users Added remarks. String remark = (String) remarks.elementAt(i); if ((remark != null) && !remark.trim().equals("")) { tTree.addRow(key + "r", " " + remark); } ResultSet col = dMeta.getColumns(null, null, name, null); while (col.next()) { String c = col.getString(4); String k1 = key + "col-" + c + "-"; tTree.addRow(k1, c, "+", color_column); String type = col.getString(6); tTree.addRow(k1 + "t", "Type: " + type); boolean nullable = col.getInt(11) != DatabaseMetaData.columnNoNulls; tTree.addRow(k1 + "n", "Nullable: " + nullable); } col.close(); tTree.addRow(key + "ind", "Indices", "+", 0); ResultSet ind = dMeta.getIndexInfo(null, null, name, false, false); String oldiname = null; while (ind.next()) { boolean nonunique = ind.getBoolean(4); String iname = ind.getString(6); String k2 = key + "ind-" + iname + "-"; if ((oldiname == null || !oldiname.equals(iname))) { tTree.addRow(k2, iname, "+", color_index); tTree.addRow(k2 + "u", "Unique: " + !nonunique); oldiname = iname; } String c = ind.getString(9); tTree.addRow(k2 + "c-" + c + "-", c); } ind.close(); } tTree.addRow("p", "Properties", "+", 0); tTree.addRow("pu", "User: "******"pr", "ReadOnly: " + cConn.isReadOnly()); tTree.addRow("pa", "AutoCommit: " + cConn.getAutoCommit()); tTree.addRow("pd", "Driver: " + dMeta.getDriverName()); tTree.addRow("pp", "Product: " + dMeta.getDatabaseProductName()); tTree.addRow("pv", "Version: " + dMeta.getDatabaseProductVersion()); } catch (SQLException e) { tTree.addRow("", "Error getting metadata:", "-", 0); tTree.addRow("-", e.getMessage()); tTree.addRow("-", e.getSQLState()); } tTree.update(); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == b) { if (makeConnection()) { if (!t1.getText().equals("") & !t2.getText().equals("") & !t3.getText().equals("") & !t4.getText().equals("")) { det dez = new det(); if (dez.date(t4.getText())) { String a = t1.getText(); String b = t2.getText(); String c = t3.getText(); String d = t4.getText(); String ef = t5.getText(); try { st = cn.createStatement(); String sql = "insert into detalle_ventas values('"; sql += a; sql += "', '"; sql += b + "', '" + c + "', '" + d + "', '" + ef; sql += "')"; int eaz = st.executeUpdate(sql); javax.swing.JOptionPane.showMessageDialog( null, "Se han creado " + eaz + " registros en la base de datos", "informacion", javax.swing.JOptionPane.INFORMATION_MESSAGE); start(); } catch (SQLException exz) { javax.swing.JOptionPane.showMessageDialog( null, "Ha ocurrido un error, favor de checar que la clave no ha sido ingresada ya con anterioridad \n si el problema persiste contacte con el administrador \nError: " + exz.getSQLState() + "" + exz.getMessage(), "Error", javax.swing.JOptionPane.INFORMATION_MESSAGE); } catch (Exception ez) { System.out.println(ez.getMessage()); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Favor de llenar la fecha con un formato correcto dd/mm/aaaa", "Error!!!", javax.swing.JOptionPane.ERROR_MESSAGE); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Favor de llenar todos los datos correctamente", "Error!!!", javax.swing.JOptionPane.ERROR_MESSAGE); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Un error ha ocurrido al intentar conectar con la base de datos, \n reinicie el componente o contacte con el administrador", "Error", javax.swing.JOptionPane.ERROR_MESSAGE); } } try { cn.close(); } catch (Exception esa) { System.out.println(esa.getMessage()); } }
/* Clear all existing nodes from the tree model and rebuild from scratch. */ protected void refreshTree() { DefaultMutableTreeNode propertiesNode; DefaultMutableTreeNode leaf; // First clear the existing tree by simply enumerating // over the root node's children and removing them one by one. while (treeModel.getChildCount(rootNode) > 0) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) treeModel.getChild(rootNode, 0); treeModel.removeNodeFromParent(child); child.removeAllChildren(); child.removeFromParent(); } treeModel.nodeStructureChanged(rootNode); treeModel.reload(); tScrollPane.repaint(); // Now rebuild the tree below its root try { // Start by naming the root node from its URL: rootNode.setUserObject(dMeta.getURL()); // get metadata about user tables by building a vector of table names String usertables[] = {"TABLE", "GLOBAL TEMPORARY", "VIEW"}; ResultSet result = dMeta.getTables(null, null, null, usertables); Vector tables = new Vector(); // sqlbob@users Added remarks. Vector remarks = new Vector(); while (result.next()) { tables.addElement(result.getString(3)); remarks.addElement(result.getString(5)); } result.close(); // For each table, build a tree node with interesting info for (int i = 0; i < tables.size(); i++) { String name = (String) tables.elementAt(i); DefaultMutableTreeNode tableNode = makeNode(name, rootNode); ResultSet col = dMeta.getColumns(null, null, name, null); // sqlbob@users Added remarks. String remark = (String) remarks.elementAt(i); if ((remark != null) && !remark.trim().equals("")) { makeNode(remark, tableNode); } // With a child for each column containing pertinent attributes while (col.next()) { String c = col.getString(4); DefaultMutableTreeNode columnNode = makeNode(c, tableNode); String type = col.getString(6); makeNode("Type: " + type, columnNode); boolean nullable = col.getInt(11) != DatabaseMetaData.columnNoNulls; makeNode("Nullable: " + nullable, columnNode); } col.close(); DefaultMutableTreeNode indexesNode = makeNode("Indices", tableNode); ResultSet ind = dMeta.getIndexInfo(null, null, name, false, false); String oldiname = null; // A child node to contain each index - and its attributes while (ind.next()) { DefaultMutableTreeNode indexNode = null; boolean nonunique = ind.getBoolean(4); String iname = ind.getString(6); if ((oldiname == null || !oldiname.equals(iname))) { indexNode = makeNode(iname, indexesNode); makeNode("Unique: " + !nonunique, indexNode); oldiname = iname; } // And the ordered column list for index components makeNode(ind.getString(9), indexNode); } ind.close(); } // Finally - a little additional metadata on this connection propertiesNode = makeNode("Properties", rootNode); makeNode("User: "******"ReadOnly: " + cConn.isReadOnly(), propertiesNode); makeNode("AutoCommit: " + cConn.getAutoCommit(), propertiesNode); makeNode("Driver: " + dMeta.getDriverName(), propertiesNode); makeNode("Product: " + dMeta.getDatabaseProductName(), propertiesNode); makeNode("Version: " + dMeta.getDatabaseProductVersion(), propertiesNode); } catch (SQLException se) { propertiesNode = makeNode("Error getting metadata:", rootNode); makeNode(se.getMessage(), propertiesNode); makeNode(se.getSQLState(), propertiesNode); } treeModel.nodeStructureChanged(rootNode); treeModel.reload(); tScrollPane.repaint(); }
/** * Handles when aides cover each other. They must tell * us who they're covering so that that poor person * doesn't get a missed shift. This of course means i * have to work on MyHours some more... If they select * a valid userid to cover for makes the appropriate * entry in AIDELOG. * * @param An SaoWorker who is covering someone else */ public void WhoRUCovering(final SaoWorker w) { int i = 0; int h = bd.getHours(); int m = bd.getMinutes(); if (((m >= 20) && (m < 30)) || ((m >= 50) && (m < 60))) { if (m < 30) { m = m + 10; } else { m = m + 10 - 60; h = h + 1; } } int dopp = bd.getDoPP(); if (dopp > 7) { dopp = dopp - 7; } String slotid = bd.getSlot(h, m, dopp); String q = "select * from AIDESCHED where " + slotid + "=1"; final String[] userids = {"", "", "", "", "", "", "", "", "", ""}; final BatSQL bSQL = new BatSQL(); ResultSet rs = bSQL.query(q); try { boolean more = rs.next(); if (more) //because there might be only one person for this slot { while (more) { userids[i] = rs.getString(1); i++; more = rs.next(); } } //end of if more } //end of try catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); System.out.println("WhoRUCovering"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.out.println("WhoRUCovering"); System.exit(0); } //end catching other Exceptions final Frame coverF = new Frame("Covering?"); final Panel p = new Panel(); final Panel btnP = new Panel(); final List coverL = new List(); Button ok = new Button("Cover"); Button nok = new Button("Cancel"); final int i2 = i; ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String id = coverL.getSelectedItem(); BatSQL bS = new BatSQL(); String a = "insert into aidelog values ('C', \"" + id + "\", \"" + bd.getDate() + "\", " + bd.getStringHours() + bd.getStringMinutes() + ", 'I')"; bS.update(a); a = "update AIDEDIN set COVERING='" + id + "' where USERID='" + w.getUserID() + "'"; bS.update(a); bS.disconnect(); coverF.dispose(); } }); nok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { coverF.dispose(); } }); btnP.setLayout(new FlowLayout()); btnP.add(ok); btnP.add(nok); p.setLayout(new BorderLayout()); p.add(new Label("Who are you covering for?"), BorderLayout.NORTH); int j; for (j = 0; j <= i; j++) { coverL.add(userids[j]); } p.add(coverL, BorderLayout.CENTER); p.add(btnP, BorderLayout.SOUTH); coverL.select(0); coverF.setLayout(new FlowLayout()); coverF.add(p); coverF.pack(); coverF.setLocation(200, 200); coverF.show(); } //end of WhoRUCovering
/** * Finds out if a SaoWorker is supposed to be working now * or not. It consults the tables AIDESCHED for this, and * if they have a entry in the current slot then they're * okay. Otherwise they're covering for somebody.<P> * * Also, if it's 10 minutes before a new slot starts this * looks at the next slot. This is to accomodate for the * fact that sometimes aides will try to Aide In a few * minutes before they're supposed to start working.<P> * * What's more, if the SaoWorker trying to AIDE IN is a * Supervisor or Programmer, the method considers them * always scheduled. How convenient! * * @param w The Aide trying to aide in * @return True scheduled for this slot, or False not */ public boolean Scheduled(SaoWorker w) { BatSQL bSQL = new BatSQL(); String q = "select * from AIDESCHED where USERID='" + w.getUserID() + "'"; ResultSet rs = bSQL.query(q); int h = bd.getHours(); int m = bd.getMinutes(); int slot = 0; int sched = 0; //first check if the worker is a Supervisor or Programmer //these two Titles are always Scheduled to work. if ((w.getTitle().equals("Supervisor")) || (w.getTitle().equals("Programmer"))) { sched = 1; } else { //aides have to be in the correct slot //this is the part where we check if they're early if (((m >= 20) && (m < 30)) || ((m >= 50) && (m < 60))) { if (m > 30) { h = h + 1; m = m + 10 - 60; } else { m = m + 10; } int dopp = bd.getDoPP(); if (dopp > 7) { dopp = dopp - 7; } slot = bd.getIntSlot(h, m, dopp); } else { int dopp = bd.getDoPP(); if (dopp > 7) { dopp = dopp - 7; } slot = bd.getIntSlot(h, m, dopp); } //now we carry on as usual try { rs.next(); sched = rs.getInt(slot+1); //+1 to skip the USERID field! } //end of try catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); System.out.println("Scheduled"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.out.println("Scheduled"); System.exit(0); } //end catching other Exceptions } //end of else this is an aide boolean scheded = (sched == 1); return scheded; } //end of Scheduled?