コード例 #1
0
  public static void showTable() {
    Vector<String> rowHeader = new Vector<String>();
    rowHeader.add("serviceID");
    rowHeader.add("serviceName");
    rowHeader.add("serviceAmount");
    DefaultTableModel model = new DefaultTableModel(rowHeader, 0);
    table.setModel(model);
    ConnectData ds = new ConnectData();
    ds.connect();
    String newSQL = "SELECT * FROM Service";
    try {
      ResultSet rs = ds.ExcuteQuery(newSQL);
      Vector<String> rowData;
      if (rs != null)
        while (rs.next()) {
          rowData = new Vector<String>();
          rowData.add(rs.getString("serviceID"));
          rowData.add(rs.getString("serviceName"));
          rowData.add(rs.getString("serviceAmount"));
          model.addRow(rowData);
        }

      rs.close();
      ds.dispose();
    } catch (Exception ex) {
      System.out.println("Error : " + ex);
    }
  }
コード例 #2
0
  public boolean updateRecord() {
    ConnectData ds = new ConnectData();
    ds.connect();
    int id = Integer.parseInt(txt_ID.getText());
    String name = txt_Name.getText();
    String amount = txt_Amount.getText();

    String sql_insert =
        "Update Service Set serviceID="
            + id
            + ",serviceName='"
            + name
            + "',serviceAmount='"
            + amount
            + "' where serviceID="
            + id;
    if (ds.queryExcuteUpdate(sql_insert)) {
      JOptionPane.showMessageDialog(null, "Successfull");
      showTable();

    } else JOptionPane.showMessageDialog(null, "fail");

    try {
      ds.dispose();
      return true;
    } catch (SQLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    return false;
  }
コード例 #3
0
  public boolean deleteRecord() {
    ConnectData ds = new ConnectData();
    ds.connect();
    String ID = txt_ID.getText();
    String sql_insert = "delete from Service where serviceID='" + ID + "'";
    if (ds.queryExcuteUpdate(sql_insert)) {
      JOptionPane.showMessageDialog(null, "delete Successfull");
      showTable();
    } else JOptionPane.showMessageDialog(null, "delete fail");

    try {
      ds.dispose();
      return true;
    } catch (SQLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    return false;
  }
コード例 #4
0
  public boolean addRecord() {
    // TODO Auto-generated method stub
    ConnectData ds = new ConnectData();
    ds.connect();
    // int id= Integer.parseInt(txt_ID.getText());
    String name = txt_Name.getText();
    String amount = txt_Amount.getText();

    String sql_insert = "insert into Service values(" + null + ",'" + name + "','" + amount + "')";
    if (ds.queryExcuteUpdate(sql_insert)) {
      JOptionPane.showMessageDialog(null, "Successfull");
      showTable();
    } else JOptionPane.showMessageDialog(null, "fail");

    try {
      ds.dispose();
      return true;
    } catch (SQLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    return false;
  }