import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.sqlite.util.StringUtils;
/**
*
}
static boolean updateNoticeBillDetails(int selid, String bill_status,
- java.util.Date bill_date, int bill_amount) {
+ java.util.Date bill_date, long bill_amount) {
try {
Connection conn = DriverManager.getConnection(JDBC + connectionURL);
PreparedStatement st = conn.prepareStatement("UPDATE legalnotices"
+ " SET BillStatus=?,BillDate=?,BillAmount=? WHERE id=?;");
st.setString (1, bill_status);
st.setDate(2, toSqlDate(bill_date));
- st.setInt(3, bill_amount);
+ st.setLong(3, bill_amount);
st.setInt(4, selid);
st.execute();
conn.close();
try {
FileWriter f = new FileWriter (filePath);
for (int i = 0; i < reportCols.length; i ++) {
- f.append (escapeQuote(reportCols[i]));
+ f.append (escapeQuoteCSV(reportCols[i]));
f.append (",");
}
f.append("\n");
for (int i = 0; i < reportData.size(); i += reportCols.length) {
for (int j = 0; j < reportCols.length; j ++) {
- f.append (escapeQuote(reportData.get(i+j)));
+ f.append (escapeQuoteCSV(reportData.get(i+j)));
f.append (",");
}
f.append ("\n");
}
- private static String escapeQuote(Object bareStr) {
- if (bareStr.getClass() == String.class) {
+ private static String escapeQuoteCSV(Object bareStr) {
+ if (bareStr == null)
+ return "";
+ else if (bareStr.getClass() == String.class) {
String str = (String)bareStr;
String escapedStr = str.replace ("\"", "\"\"");
System.out.println(escapedStr);
return String.format("\"%s\"", bareStr.toString());
}
+ static boolean saveReportHTML(String filepath, String report_title,
+ String[] report_cols, ArrayList<Object> report_data) {
+ FileWriter htmlFile;
+ try {
+ htmlFile = new FileWriter(filepath);
+ htmlFile.append("<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<title>");
+ htmlFile.append(htmlEscape(report_title));
+ htmlFile.append("</title>\n</head>\n");
+ htmlFile.append ("<body>\n");
+ htmlFile.append("<h1>");
+ htmlFile.append(htmlEscape(report_title));
+ htmlFile.append("</h1>\n");
+ htmlFile.append ("<table>\n");
+ htmlFile.append ("\t<tr>\n");
+ for (int i = 0; i < report_cols.length; i ++) {
+ htmlFile.append ("\t\t<th>");
+ htmlFile.append (htmlEscape(report_cols[i]));
+ htmlFile.append("</th>\n");
+ }
+ htmlFile.append ("\t</tr>\n");
+ for (int r = 0; r < report_data.size(); r += report_cols.length) {
+ htmlFile.append("\t<tr>\n");
+ for (int c = 0; c < report_cols.length; c ++) {
+ htmlFile.append("\t\t<td>");
+ htmlFile.append(htmlEscape(report_data.get(r+c)));
+ htmlFile.append("</td>\n");
+ }
+ htmlFile.append ("\t</tr>\n");
+ }
+ htmlFile.append("</table>\n");
+ htmlFile.append("</body>\n");
+ htmlFile.append("</html>");
+ htmlFile.flush();
+ htmlFile.close();
+ return true;
+ } catch (IOException ex) {
+ Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+ return false;
+ }
+ }
+
+ private static String htmlEscape(Object barestr) {
+ if (barestr == null)
+ return "";
+ else if (barestr.getClass() == String.class) {
+ String barestrs = (String)barestr;
+ String str = barestrs.replace("&", "&").replace("<", "<").
+ replace(">", ">").replace("\"", """).replace("\n", "<br>");
+ return str;
+ }
+ else
+ return barestr.toString();
+ }
+
public Utility () {