예제 #1
0
  public static void main(String args[]) {
    String database = "tmcprogram3";
    String url = "jdbc:mysql://localhost:3306/" + database + "?zeroDateTimeBehavior=convertToNull";
    String username = "******";
    String password = "******";

    boolean result = MySqlDBHelper.init(url, username, password);

    ArrayList<InvoiceTemplate> items = InvoiceTemplate.select("");
    for (InvoiceTemplate item : items) {
      System.out.println(item);
    }
    System.out.println(InvoiceTemplate.count(""));
  }
예제 #2
0
 // -----------database helper functions--------------
 public static String implodeValues(InvoiceTemplate item, boolean withId) {
   ArrayList<String> values = item.implodeFieldValuesHelper(withId);
   String output = "";
   for (String value : values) {
     if (!output.isEmpty()) output += ",";
     output += "'" + value + "'";
   }
   return output;
 }
예제 #3
0
  public static String implodeFieldsWithValues(InvoiceTemplate item, boolean withId) {
    ArrayList<String> values =
        item.implodeFieldValuesHelper(
            true); // get entire list of values; whether the id is included will be dealt with
                   // later.

    if (values.size() != fields.length) {
      System.err.println(
          "InvoiceTemplate:implodeFieldsWithValues(): ERROR: values length does not match fields length");
    }

    String output = "";
    for (int i = 0; i < fields.length; i++) {
      if (!withId && fields[i].contentEquals("id")) continue;
      if (!output.isEmpty()) output += ",";
      output += fields[i] + "='" + values.get(i) + "'";
    }
    return output;
  }
예제 #4
0
 public static void update(InvoiceTemplate item) {
   Connection conn = MySqlDBHelper.getInstance().getConnection();
   Statement st = null;
   boolean withid = false;
   try {
     st = conn.createStatement();
     st.executeUpdate(
         "update "
             + tablename
             + " set "
             + implodeFieldsWithValues(item, false)
             + " where id = '"
             + item.getId().toString()
             + "';");
   } catch (SQLException ex) {
     Logger.getLogger(InvoiceTemplate.class.getName()).log(Level.SEVERE, null, ex);
     ex.printStackTrace();
   }
 }
예제 #5
0
 public void save() {
   if (id == null || id == 0) InvoiceTemplate.insert(this);
   else InvoiceTemplate.update(this);
 }
예제 #6
0
 public void delete() {
   InvoiceTemplate.delete(this);
 }
예제 #7
0
 public static void delete(InvoiceTemplate item) {
   delete(item.getId());
 }