public void actionPerformed(ActionEvent e) { int k = 0; try { rs = statement.executeQuery("select * from hostelStatus"); while (rs.next()) { data[k][0] = rs.getString(1); data[k][1] = rs.getString(2); data[k][2] = rs.getString(3); k++; } data[k][0] = " "; data[k][1] = " "; data[k][2] = " "; table = new JTable(data, col); table.setFont(new Font("Serif", Font.BOLD, 16)); table.setBackground(new Color(250, 250, 250)); JScrollPane jsp = new JScrollPane(table); jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jsp.setBounds(5, 100, 590, 200); cn.add(jsp); } catch (Exception sq) { JOptionPane.showMessageDialog(null, "error" + sq); } }
public void updateRecord() { String totalSeat, alotSeat, vacentSeat, strHostel; try { rs = statement.executeQuery("select hostelName from hostelStatus"); while (rs.next()) { strHostel = rs.getString(1); try { rs1 = statement1.executeQuery("select count(*) from " + strHostel + ""); rs1.next(); totalSeat = rs1.getString(1); rs1 = statement1.executeQuery("select count(*) from " + strHostel + " where status='F'"); rs1.next(); alotSeat = rs1.getString(1); try { vacentSeat = String.valueOf(Integer.parseInt(totalSeat) - Integer.parseInt(alotSeat)); statement1.executeUpdate( "update hostelStatus set totalSeat='" + totalSeat + "',vacentSeat='" + vacentSeat + "'where hostelName='" + strHostel + "'"); statement1.executeUpdate("commit"); rs1.close(); } catch (SQLException sqle) { JOptionPane.showMessageDialog(null, sqle); } } catch (SQLException sqle) { JOptionPane.showMessageDialog(null, "Error " + sqle); } } } catch (SQLException sq) { JOptionPane.showMessageDialog(null, sq); } }
public void connect() { try { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/root", "root", ""); statement = connection.createStatement(); statement1 = connection.createStatement(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "JavaError:Not Connect"); } }
protected void processWindowEvent(WindowEvent we) { if (we.getID() == we.WINDOW_CLOSING) { r = JOptionPane.showConfirmDialog(null, "WARNNING", "EXIT", JOptionPane.WARNING_MESSAGE); if (r == JOptionPane.YES_OPTION) dispose(); } }
public void actionPerformed(ActionEvent e) { int n = JOptionPane.showConfirmDialog( null, "Would U Really Want To Exit", "Enter Carefully", JOptionPane.WARNING_MESSAGE); if (n == JOptionPane.YES_OPTION) dispose(); }