posted 6 years ago
[quote]What does your code look like? Maybe all you need are fresh pair(s) of eyes to see what's going wrong. [/quote]
Hi again,
This is obviously a work in progress, but I think you can get the idea. Thanks for taking the time.
[code=java]/*
import java.io.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.util.Date;
import static java.lang.System.*;
public class BillingReportsStagingCounts {
private static final Integer ZERO = new Integer("0");
private static String getActiveSchemas = "SELECT ACCOUNT_ID. ACCOUNT_NAME, BOARDED_FLAG, SCHEMA_CD, CLASS " +
"FROM table1 AX " +
"JOIN table2 CC ON AX.GSMRT_ID = CC.COMPANY_ID " +
"JOIN table3 SC ON TBCREATOR = SC.SCHEMA_CD " +
"WHERE TBNAME IS NOT NULL";
private static String getCount = "SELECT COUNT(*) \"COUNT\" FROM %schema%.%table% WHERE %date_field% BETWEEN" +
" '%lfm_day1%' AND '%lfm_day2%'";
private static String connectionData1 = "jdbc:1.2.3.4:5000/SCHEMA1";
private static String connectionData2 = "jdbc:2.3.4.6:4000/SCHEMA2";
private static String userId1 = "mardeq";
private static String password1 = "XXX";
private static String userId2 = "marilyn";
private static String password2 = "yYY";
private static Timestamp startDttm;
private static Timestamp stopDttm;
private static Writer writer = null;
private static Calendar firstDateOfLFM;
private static Timestamp currentTimestamp;
// load new driver
static {
}
// get Report Dates
static {
firstDateOfLFM = Calendar.getInstance();
Calendar lastDateOfLFM = Calendar.getInstance();
startDttm = new Timestamp(firstDateOfLFM.getTimeInMillis());
stopDttm = new Timestamp(lastDateOfLFM.getTimeInMillis());
currentTimestamp = new Timestamp(System.currentTimeMillis());
}
// write csv file
private static void writeResults(List dataList, String fileName) {
System.out.println("Printing");
try {
writer = new BufferedWriter(new FileWriter(fileName));
// write headers
Map firstRecord = (Map)dataList.get(0);
Set headerKeys = firstRecord.keySet();
Iterator iterator = headerKeys.iterator();
while (iterator.hasNext()) {
writer.write((String)iterator.next());
writer.write(",");
}
writer.write("\n");
writer.flush();
// write values
for (int i = 0; i < dataList.size(); i++) {
Map data = (Map)dataList.get(i);
Set keys = data.keySet();
iterator = keys.iterator();
while (iterator.hasNext()) {
String key = (String)iterator.next();
String field = (data.get(key).toString());
writer.write(field);
writer.write(",");
}
SimpleDateFormat dfYearMonth = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat dfYearMonthDay = new SimpleDateFormat("yyyy-MM-dd");
String sd = dfYearMonth.format(startDttm);
writer.write(sd + ",");
String currDt = dfYearMonthDay.format(currentTimestamp);
writer.write(currDt);
writer.write("\n");
writer.flush();
}
} catch (Exception e) {
System.out.println("Unable to get file writer");
}
}
private static ResultSet executeCountSql(Statement statement, String schema, String sql, ResultSet rs) {
if (sql.length() > 0) {
try {
rs = statement.executeQuery(sql);
} catch (SQLException e) {}
return rs;
}
private static List
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt