public boolean updateDatabase( String table_name, String table_column_giving, Object row_element, String table_column_giving2, Object row_element2, String table_column_need, Object update_element) { // DatabaseManager dbm = DatabaseManager.getDbCon(); try { dbm.insert( "UPDATE " + table_name + " SET " + table_column_need + " ='" + update_element + "' WHERE " + table_column_giving + "='" + row_element + "' AND " + table_column_giving2 + "='" + row_element2 + "'"); } catch (SQLException ex) { MessageBox.showMessage(ex.getMessage(), "SQL ERROR", "error"); return false; } return true; }
private void jButton1ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed row = 0; while (table.getValueAt(row, 0) != null) { workingdays = Short.valueOf((table.getValueAt(row, 1).toString())); if (checkDataAvailability( "prcr_margin_dates", "month", month, "division", table.getValueAt(row, 0).toString(), "margin")) { updateDatabase( "prcr_margin_dates", "month", month, "division", table.getValueAt(row, 0).toString(), "total", workingdays); updateDatabase( "prcr_margin_dates", "month", month, "division", table.getValueAt(row, 0).toString(), "margin", Math.floor(workingdays * 0.75)); } else { try { dbm.insert( "INSERT INTO prcr_margin_dates(month,division,margin,total) VALUES('" + month + "','" + table.getValueAt(row, 0).toString() + "','" + Math.floor(workingdays * 0.75) + "','" + workingdays + "')"); } catch (SQLException ex) { Logger.getLogger(PRCR_change_margin_dates.class.getName()).log(Level.SEVERE, null, ex); } } row++; } initialFill(month); JOptionPane.showMessageDialog(null, "Saved\n", "Message", JOptionPane.INFORMATION_MESSAGE); // System.out.println("month,row-"+month+row); } // GEN-LAST:event_jButton1ActionPerformed
public boolean fillDatabase( String table_name, String table_column_giving1, Object row_element1, String table_column_giving2, Object row_element2, String table_column_need, Object update_element) { // if (checkDataAvailability("prcr_margin_dates", "month", st, "division", division, // "margin")) { // updateDatabase("prcr_margin_dates", "month", st, "division", division, // "total", workingdays); // updateDatabase("prcr_margin_dates", "month", st, "division", division, // "margin", Math.floor(workingdays * 0.75)); // } else { // dbm.insert("INSERT INTO prcr_margin_dates(month,division,margin,total) // VALUES('" + st + "','" + division + "','" + Math.floor(workingdays * 0.75) + "','" + // workingdays + "')"); // } // // // DatabaseManager dbm = DatabaseManager.getDbCon(); try { dbm.insert( "UPDATE " + table_name + " SET " + table_column_need + " ='" + update_element + "' where " + table_column_giving1 + " LIKE '" + row_element1 + "' AND " + table_column_giving2 + " LIKE '" + row_element2 + "'"); } catch (SQLException ex) { MessageBox.showMessage(ex.getMessage(), "SQL ERROR", "error"); return false; } return true; }
/** * Main method to control data flow. This function takes the command line parameter as input and * uses it to read from the input file, executing and outputting commands along the way. * * @param args - the command line arguments */ public static void main(String[] args) { // Check for proper usage if (args.length != 1) { System.out.println("Usage:"); System.out.println("P3 COMMAND_FILE"); System.exit(0); } String fileName = args[0]; tree = new DNATree(); dbm = new DatabaseManager(); // Main command line reading try { // Attempt to open the input file into a buffered reader BufferedReader in = new BufferedReader(new FileReader(fileName)); // Keep reading in commands until we reach the EOF String line; while ((line = in.readLine()) != null) { if (line.matches(INSERT_PATTERN)) { // Parse out the sequence id and length from the command line int begin = Math.max(line.indexOf("r"), line.indexOf("R")) + 2; int end = Math.max( Math.max( Math.max(line.lastIndexOf('A'), line.lastIndexOf('C')), line.lastIndexOf('G')), line.lastIndexOf('T')) + 1; String sequence = line.substring(begin, end); sequence = sequence.trim(); int length = Integer.parseInt(line.substring(end).trim()); if (length <= 0) { System.out.println("Length less than zero."); continue; } // Get the next line for the sequence String entry = in.readLine(); // Add to the dbm Handle handle = dbm.insert(entry, length); // Add to tree int result = tree.insert(sequence, handle); if (result < 0) { dbm.remove(handle); System.out.println("Sequence " + sequence + " already in tree."); } else { System.out.println("Sequence " + sequence + " inserted at level " + result + "."); } System.out.println(); } else if (line.matches(REMOVE_PATTERN)) { // Parse out the sequence id from the command line int index = Math.max(line.indexOf("v"), line.indexOf("V")) + 2; String sequence = line.substring(index); sequence = sequence.trim(); // Remove sequence id from tree Handle handle = tree.remove(sequence); // Remove sequence from dbm if (handle == null) { System.out.println("Sequence " + sequence + " not found in tree."); System.out.println(); } else { dbm.remove(handle); } } else if (line.matches(PRINT_PATTERN)) { // Output the tree System.out.println(tree); // Output free blocks System.out.println(dbm); System.out.println(); } else if (line.matches(SEARCH_PATTERN)) { // Parse out the sequence id from the command line int index = Math.max(line.indexOf("h"), line.indexOf("H")) + 1; String sequence = line.substring(index); sequence = sequence.trim(); // Search the tree for handles String results = tree.search(sequence); Scanner scan = new Scanner(results); String output = scan.nextLine() + "\n"; // Augment output with results from dbm String entry; int offset, length; Handle handle; while (scan.hasNextLine()) { entry = scan.nextLine(); if (entry.matches(KEY_PATTERN)) { output += entry + "\n"; } else if (entry.matches(HANDLE_PATTERN)) { // Parse out offset and length offset = Integer.parseInt(entry.substring(entry.indexOf('[') + 1, entry.indexOf(','))); length = Integer.parseInt(entry.substring(entry.indexOf(',') + 2, entry.indexOf(']'))); // Create handle and use it to query database handle = new Handle(offset, length); output += "Sequence:\n" + dbm.getEntry(handle) + "\n"; } else { continue; } } scan.close(); System.out.println(output.substring(0, output.length() - 1)); System.out.println(); } else { continue; } } in.close(); } catch (FileNotFoundException e) { System.out.println("The input file could not be found."); System.exit(0); } catch (IOException e) { System.out.println("Error reading from file."); System.exit(0); } catch (Exception e) { System.out.println("Incorrect file formatting."); e.printStackTrace(); System.exit(0); } }