コード例 #1
0
    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);
      }
    }
コード例 #2
0
  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);
    }
  }
コード例 #3
0
  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");
    }
  }