List of usage examples for java.sql ResultSetMetaData getColumnName
String getColumnName(int column) throws SQLException;
From source file:rems.Global.java
public static void exprtDtStToCSV(ResultSet dtst, String csvfileNm, boolean isfirst, boolean islast, boolean shdAppnd, String rptdlmtr) { try {//w w w .ja v a2 s. c o m if (isfirst) { } dtst.last(); int totl = dtst.getRow(); dtst.beforeFirst(); ResultSetMetaData dtstmd = dtst.getMetaData(); String hdrNms = ""; String lineVals = ""; String dlmtr = ""; if (isfirst) { } /*None Comma (,) Semi-Colon(;) Pipe(|) Tab Tilde(~)*/ if (rptdlmtr.equals("None") || rptdlmtr.equals("Pipe(|)")) { dlmtr = "|"; } else if (rptdlmtr.equals("Comma (,)")) { dlmtr = ","; } else if (rptdlmtr.equals("Semi-Colon(;)")) { dlmtr = ";"; } else if (rptdlmtr.equals("Tab")) { dlmtr = "\t"; } else if (rptdlmtr.equals("Tilde(~)")) { dlmtr = "~"; } else { dlmtr = "|"; } int collen = 0; int colcnt = dtstmd.getColumnCount(); for (int a = 0; a < colcnt; a++) { collen = dtstmd.getColumnName(a + 1).length(); if (collen >= 3) { hdrNms += dtstmd.getColumnName(a + 1) + dlmtr; } } if (hdrNms.length() > 0) { Global.strSB.append(hdrNms.substring(0, hdrNms.length() - 1)) .append(System.getProperty("line.separator")); } //Global.strSB.append(hdrNms); for (int i = 0; i < totl; i++) { dtst.next(); lineVals = ""; for (int a = 0; a < colcnt; a++) { collen = dtstmd.getColumnName(a + 1).length(); if (collen >= 3) { lineVals += dtst.getString(a + 1) + dlmtr; } } if (lineVals.length() > 0) { Global.strSB.append(lineVals.substring(0, lineVals.length() - 1)) .append(System.getProperty("line.separator")); } } if (islast) { File file = new File(csvfileNm); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); bw.write(Global.strSB.toString()); bw.close(); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/" + String.valueOf(Global.runID) + ".csv"); } } } catch (SQLException ex) { } catch (IOException ex) { } }
From source file:edu.ku.brc.specify.ui.db.ResultSetTableModel.java
@Override //@SuppressWarnings("null") public synchronized void exectionDone(final SQLExecutionProcessor process, final ResultSet resultSet) { if (statusBar != null) { statusBar.incrementValue(getClass().getSimpleName()); }/* w w w . j a v a 2 s. co m*/ if (resultSet == null || results == null) { log.error("The " + (resultSet == null ? "resultSet" : "results") + " is null."); if (propertyListener != null) { propertyListener.propertyChange(new PropertyChangeEvent(this, "rowCount", null, 0)); } return; } List<ERTICaptionInfo> captions = results.getVisibleCaptionInfo(); // This can do one of two things: // 1) Take multiple columns and create an object and use a DataObjectFormatter to format the object. // 2) Table multiple objects that were derived from the columns and roll those up into a single column's value. // This happens when you get back rows of info where part of the columns are duplicated because you really // want those value to be put into a single column. // // Step One - Is to figure out what type of object needs to be created and what the Columns are // that need to be set into the object so the dataObjFormatter can do its job. // // Step Two - If the objects are being aggregated then the object created from the columns are added to a List // and then last formatted as an "aggregation" try { if (resultSet.next()) { ResultSetMetaData metaData = resultSet.getMetaData(); // Composite boolean hasCompositeObj = false; DataObjSwitchFormatter dataObjFormatter = null; UIFieldFormatterIFace formatter = null; Object compObj = null; // Aggregates ERTICaptionInfo aggCaption = null; ERTICaptionInfo compositeCaption = null; Vector<Object> aggList = null; DataObjectSettable aggSetter = null; Stack<Object> aggListRecycler = null; DataObjectSettable dataSetter = null; // data getter for Aggregate or the Subclass // Loop through the caption to figure out what columns will be displayed. // Watch for Captions with an Aggregator or Composite numColumns = captions.size(); for (ERTICaptionInfo caption : captions) { colNames.addElement(caption.getColLabel()); int inx = caption.getPosIndex() + 1; //log.debug(metaData.getColumnClassName(inx)); Class<?> cls = null; try { cls = Class.forName(metaData.getColumnClassName(inx)); if (cls == Calendar.class || cls == java.sql.Date.class || cls == Date.class) { cls = String.class; } } catch (SQLException ex) { cls = String.class; } classNames.addElement(cls); caption.setColClass(cls); if (caption.getAggregatorName() != null) { //log.debug("The Agg is ["+caption.getAggregatorName()+"] "+caption.getColName()); // Alright we have an aggregator aggList = new Vector<Object>(); aggListRecycler = new Stack<Object>(); aggCaption = caption; aggSetter = DataObjectSettableFactory.get(aggCaption.getAggClass().getName(), FormHelper.DATA_OBJ_SETTER); // Now check to see if we are aggregating the this type of object or a child object of this object // For example Collectors use an Agent as part of the aggregation if (aggCaption.getSubClass() != null) { dataSetter = DataObjectSettableFactory.get(aggCaption.getSubClass().getName(), FormHelper.DATA_OBJ_SETTER); } else { dataSetter = aggSetter; } } else if (caption.getColInfoList() != null) { formatter = caption.getUiFieldFormatter(); if (formatter != null) { compositeCaption = caption; } else { // OK, now aggregation but we will be rolling up multiple columns into a single object for formatting // We need to get the formatter to see what the Class is of the object hasCompositeObj = true; aggCaption = caption; dataObjFormatter = caption.getDataObjFormatter(); if (dataObjFormatter != null) { if (dataObjFormatter.getDataClass() != null) { aggSetter = DataObjectSettableFactory.get( dataObjFormatter.getDataClass().getName(), "edu.ku.brc.af.ui.forms.DataSetterForObj"); } else { log.error("formatterObj.getDataClass() was null for " + caption.getColName()); } } else { log.error("DataObjFormatter was null for " + caption.getColName()); } } } //colNames.addElement(metaData.getColumnName(i)); //System.out.println("**************** " + caption.getColLabel()+ " "+inx+ " " + caption.getColClass().getSimpleName()); } // aggCaption will be non-null for both a Aggregate AND a Composite if (aggCaption != null) { // Here we need to dynamically discover what the column indexes are that we to grab // in order to set them into the created data object for (ERTICaptionInfo.ColInfo colInfo : aggCaption.getColInfoList()) { for (int i = 0; i < metaData.getColumnCount(); i++) { String colName = StringUtils.substringAfterLast(colInfo.getColumnName(), "."); if (colName.equalsIgnoreCase(metaData.getColumnName(i + 1))) { colInfo.setPosition(i); break; } } } // Now check to see if there is an Order Column because the Aggregator // might need it for sorting the Aggregation String ordColName = aggCaption.getOrderCol(); if (StringUtils.isNotEmpty(ordColName)) { String colName = StringUtils.substringAfterLast(ordColName, "."); //log.debug("colName ["+colName+"]"); for (int i = 0; i < metaData.getColumnCount(); i++) { //log.debug("["+colName+"]["+metaData.getColumnName(i+1)+"]"); if (colName.equalsIgnoreCase(metaData.getColumnName(i + 1))) { aggCaption.setOrderColIndex(i); break; } } if (aggCaption.getOrderColIndex() == -1) { log.error("Agg Order Column Index wasn't found [" + ordColName + "]"); } } } if (ids == null) { ids = new Vector<Integer>(); } else { ids.clear(); } // Here is the tricky part. // When we are doing a Composite we are just taking multiple columns and // essentially replace them with a single value from the DataObjFormatter // // But when doing an Aggregation we taking several rows and rolling them up into a single value. // so this code knows when it is doing an aggregation, so it knows to only add a new row to the display-able // results when primary id changes. DataObjFieldFormatMgr dataObjMgr = DataObjFieldFormatMgr.getInstance(); Vector<Object> row = null; boolean firstTime = true; int prevId = Integer.MAX_VALUE; // really can't assume any value but will choose Max int numCols = resultSet.getMetaData().getColumnCount(); do { int id = resultSet.getInt(1); //log.debug("id: "+id+" prevId: "+prevId); // Remember aggCaption is used by both a Aggregation and a Composite if (aggCaption != null && !hasCompositeObj) { if (firstTime) { prevId = id; row = new Vector<Object>(); firstTime = false; cache.add(row); ids.add(id); } else if (id != prevId) { //log.debug("Agg List len: "+aggList.size()); if (row != null && aggList != null) { int aggInx = captions.indexOf(aggCaption); row.remove(aggInx); row.insertElementAt(dataObjMgr.aggregate(aggList, aggCaption.getAggClass()), aggInx); if (aggListRecycler != null) { aggListRecycler.addAll(aggList); } aggList.clear(); row = new Vector<Object>(); cache.add(row); ids.add(id); } prevId = id; } else if (row == null) { row = new Vector<Object>(); cache.add(row); ids.add(id); } } else { row = new Vector<Object>(); cache.add(row); ids.add(id); } // Now for each Caption column get a value for (ERTICaptionInfo caption : captions) { int posIndex = caption.getPosIndex(); if (caption == aggCaption) // Checks to see if we need to take multiple columns and make one column { if (hasCompositeObj) // just doing a Composite { if (aggSetter != null && row != null && dataObjFormatter != null) { if (compObj == null) { compObj = aggCaption.getAggClass().newInstance(); } for (ERTICaptionInfo.ColInfo colInfo : aggCaption.getColInfoList()) { setField(aggSetter, compObj, colInfo.getFieldName(), colInfo.getFieldClass(), resultSet, colInfo.getPosition()); } row.add(DataObjFieldFormatMgr.getInstance().format(compObj, compObj.getClass())); } else if (formatter != null) { int len = compositeCaption.getColInfoList().size(); Object[] val = new Object[len]; int i = 0; for (ERTICaptionInfo.ColInfo colInfo : compositeCaption.getColInfoList()) { int colInx = colInfo.getPosition() + posIndex + 1; if (colInx < numCols) { val[i++] = resultSet.getObject(colInx); } else { //val[i++] = resultSet.getObject(posIndex+1); val[i++] = "(Missing Data)"; } } row.add(formatter.formatToUI(val)); } else { log.error("Aggregator is null! [" + aggCaption.getAggregatorName() + "] or row or aggList"); } } else if (aggSetter != null && row != null && aggList != null) // Doing an Aggregation { Object aggObj; if (aggListRecycler.size() == 0) { aggObj = aggCaption.getAggClass().newInstance(); } else { aggObj = aggListRecycler.pop(); } Object aggSubObj = aggCaption.getSubClass() != null ? aggCaption.getSubClass().newInstance() : null; aggList.add(aggObj); //@SuppressWarnings("unused") //DataObjAggregator aggregator = DataObjFieldFormatMgr.getInstance().getAggregator(aggCaption.getAggregatorName()); //log.debug(" aggCaption.getOrderColIndex() "+ aggCaption.getOrderColIndex()); //aggSetter.setFieldValue(aggObj, aggregator.getOrderFieldName(), resultSet.getObject(aggCaption.getOrderColIndex() + 1)); Object dataObj; if (aggSubObj != null) { aggSetter.setFieldValue(aggObj, aggCaption.getSubClassFieldName(), aggSubObj); dataObj = aggSubObj; } else { dataObj = aggObj; } for (ERTICaptionInfo.ColInfo colInfo : aggCaption.getColInfoList()) { setField(dataSetter, dataObj, colInfo.getFieldName(), colInfo.getFieldClass(), resultSet, colInfo.getPosition()); } row.add("PlaceHolder"); } else if (aggSetter == null || aggList == null) { log.error("Aggregator is null! [" + aggCaption.getAggregatorName() + "] or aggList[" + aggList + "]"); } } else if (row != null) { if (caption.getColName() == null && caption.getColInfoList().size() > 0) { int len = caption.getColInfoList().size(); Object[] val = new Object[len]; for (int i = 0; i < caption.getColInfoList().size(); i++) { int inx = posIndex + 1 + i; val[i] = caption.processValue(resultSet.getObject(inx)); } row.add(caption.getUiFieldFormatter().formatToUI(val)); //col += caption.getColInfoList().size() - 1; } else { Object obj = caption.processValue(resultSet.getObject(posIndex + 1)); row.add(obj); } } } } while (resultSet.next()); // We were always setting the rolled up data when the ID changed // but on the last row we need to do it here manually (so to speak) if (aggCaption != null && aggList != null && aggList.size() > 0 && row != null) { int aggInx = captions.indexOf(aggCaption); row.remove(aggInx); String colStr; if (StringUtils.isNotEmpty(aggCaption.getAggregatorName())) { colStr = DataObjFieldFormatMgr.getInstance().aggregate(aggList, aggCaption.getAggregatorName()); } else { colStr = DataObjFieldFormatMgr.getInstance().aggregate(aggList, aggCaption.getAggClass()); } row.insertElementAt(colStr, aggInx); aggList.clear(); aggListRecycler.clear(); } fireTableStructureChanged(); fireTableDataChanged(); } } catch (Exception ex) { ex.printStackTrace(); } if (propertyListener != null) { propertyListener .propertyChange(new PropertyChangeEvent(this, "rowCount", null, new Integer(cache.size()))); } }
From source file:rems.Global.java
public static void exprtToHTMLDet(ResultSet recsdtst, ResultSet grpsdtst, String fileNm, String rptTitle, boolean isfirst, boolean islast, boolean shdAppnd, String orntnUsd, String imgCols) { try {/*from w w w . jav a 2 s .com*/ imgCols = "," + StringUtils.strip(imgCols, ",") + ","; String cption = ""; if (isfirst) { cption = "<caption align=\"top\">" + rptTitle + "</caption>"; Global.strSB.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"[]><html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-US\" xml:lang=\"en\"><head><meta http-equiv=\"Content-Type\" " + "content=\"text/html; charset=utf-8\">" + System.getProperty("line.separator") + "<title>" + rptTitle + "</title>" + System.getProperty("line.separator") + "<link rel=\"stylesheet\" href=\"../amcharts/rpt.css\" type=\"text/css\"></head><body>"); Files.copy( new File(Global.getOrgImgsDrctry() + "/" + String.valueOf(Global.UsrsOrg_ID) + ".png") .toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.UsrsOrg_ID) + ".png").toPath(), StandardCopyOption.REPLACE_EXISTING); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/amcharts_2100/images/" + String.valueOf(Global.UsrsOrg_ID) + ".png"); } //Org Name String orgNm = Global.getOrgName(Global.UsrsOrg_ID); String pstl = Global.getOrgPstlAddrs(Global.UsrsOrg_ID); //Contacts Nos String cntcts = Global.getOrgContactNos(Global.UsrsOrg_ID); //Email Address String email = Global.getOrgEmailAddrs(Global.UsrsOrg_ID); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.UsrsOrg_ID) + ".png\">" + orgNm + "<br/>" + pstl + "<br/>" + cntcts + "<br/>" + email + "<br/>" + "</p>") .append(System.getProperty("line.separator")); } int fullPgWdthVal = 800; if (orntnUsd.equals("Portrait")) { fullPgWdthVal = 700; } int wdth = 0; String finalStr = " "; String algn = "left"; String[] rptGrpVals = { "Group Title", "Group Page Width Type", "Group Min-Height", "Show Group Border", "Group Display Type", "No of Vertical Divs In Group", "Comma Separated Col Nos", "Data Label Max Width%", "Comma Separated Hdr Nms", "Column Delimiter", "Row Delimiter" }; String grpTitle = ""; String grpPgWdth = ""; int grpMinHght = 0; String shwBrdr = "Show"; String grpDsplyTyp = "Details"; int grpColDvsns = 4;//Use 1 for Images others 2 or 4 String colnums = ""; String lblmaxwdthprcnt = "35"; String tblrHdrs = ""; String clmDlmtrs = ""; String rwDlmtrs = ""; int divwdth = 0; /* 1. For each detail group create a div and fieldset with legend & border based on group settings * 2a. if detail display then create required no of td in tr1 of a table, create new tr if no of columns is not exhausted * i.e if no of vertical divs=4 no rows=math.ceil(no cols*0.5)/ * else no rows=no cols * for each col display label and data if vrtcl divs is 2 or 4 else display only data * 2b. if tabular create table with headers according to defined headers * split data according to rows and cols and display them in this table * 2. Get all column nos within the group and create their labels and data using settings * 3. if col nos is image then use full defined page width else create no of defined columns count * 4. if * */ grpsdtst.last(); recsdtst.last(); int grpdtcnt = grpsdtst.getRow(); int rowsdtcnt = recsdtst.getRow(); grpsdtst.beforeFirst(); recsdtst.beforeFirst(); ResultSetMetaData recsdtstmd = recsdtst.getMetaData(); ResultSetMetaData grpsdtstmd = grpsdtst.getMetaData(); for (int a = 0; a < rowsdtcnt; a++) { recsdtst.next(); Global.strSB.append("<table style=\"margin-top:5px;min-width:" + String.valueOf(fullPgWdthVal + 50) + "px;\">" + cption + "<tbody>").append(System.getProperty("line.separator")); Global.strSB.append("<tr><td>").append(System.getProperty("line.separator")); for (int d = 0; d < grpdtcnt; d++) { grpsdtst.next(); wdth = 35; grpTitle = grpsdtst.getString(1); grpPgWdth = grpsdtst.getString(2); grpMinHght = Integer.parseInt(grpsdtst.getString(3)); shwBrdr = grpsdtst.getString(4); grpDsplyTyp = grpsdtst.getString(5); grpColDvsns = Integer.parseInt(grpsdtst.getString(6));//Use 1 for Images others 2 or 4 colnums = grpsdtst.getString(7); lblmaxwdthprcnt = grpsdtst.getString(8); tblrHdrs = grpsdtst.getString(9); clmDlmtrs = grpsdtst.getString(10); rwDlmtrs = grpsdtst.getString(11); wdth = Integer.parseInt(lblmaxwdthprcnt); if (grpPgWdth.equals("Half Page Width")) { divwdth = (int) (fullPgWdthVal / 2); } else { divwdth = (int) (fullPgWdthVal / 1); } Global.strSB.append("<div style=\"float:left;min-width:" + String.valueOf(divwdth - 50) + "px;padding:10px;\">").append(System.getProperty("line.separator"));//min-height:" + (grpMinHght + 20).ToString() + "px; if (shwBrdr.equals("Show")) { Global.strSB .append("<fieldset style=\"min-width:" + String.valueOf(divwdth - 80) + "px;\">") .append(System.getProperty("line.separator"));//min-height:" + (grpMinHght).ToString() + "px; Global.strSB.append("<legend>" + grpTitle + "</legend>") .append(System.getProperty("line.separator")); } String w = "\\,"; String[] colNumbers = colnums.split(w); int noofRws = 1; wdth = ((divwdth - 90) * wdth) / 100; if (grpDsplyTyp.equals("DETAIL")) { if (grpColDvsns == 4) { noofRws = (int) Math.ceil((double) colNumbers.length / (double) 2); } else { noofRws = colNumbers.length; } Global.strSB .append("<table style=\"min-width:" + String.valueOf(divwdth - 90) + "px;margin-top:5px;border:none;\" border=\"0\"><tbody>") .append(System.getProperty("line.separator")); if (grpColDvsns == 4) { for (int h = 0; h < colNumbers.length; h++) { if ((h % 2) == 0) { Global.strSB.append("<tr>").append(System.getProperty("line.separator")); } int clnm = -1; clnm = Integer.parseInt(colNumbers[h]); if (clnm >= 0) { String frsh = ""; Global.strSB.append( "<td style=\"border-bottom:none;border-left:none;font-weight:bolder;\" align=\"" + algn + "\" width=\"" + wdth + "px\">") .append(System.getProperty("line.separator")); frsh = recsdtstmd.getColumnName(clnm + 1).trim() + ": "; Global.strSB.append( Global.breakTxtDownHTML(frsh, (wdth / 7)).replace(" ", " ")); Global.strSB.append("</td>").append(System.getProperty("line.separator")); Global.strSB .append("<td style=\"border-bottom:none;border-left:none;\" align=\"" + algn + "\" width=\"" + (divwdth - 90 - wdth) + "px\">") .append(System.getProperty("line.separator")); if (imgCols.contains("," + clnm + ",")) { frsh = recsdtst.getString(clnm + 1).trim(); File file = new File(Global.dataBasDir + frsh); // if file doesnt exists, then create it if (!file.exists()) { String extnsn = FilenameUtils.getExtension(Global.dataBasDir + frsh); Files.copy(new File(Global.dataBasDir + frsh).toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn).toPath(), StandardCopyOption.REPLACE_EXISTING); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn + "\" style=\"width:auto;height::" + grpMinHght + "px;\">" + "</p>") .append(System.getProperty("line.separator")); } } else { frsh = recsdtst.getString(clnm + 1).trim() + " "; Global.strSB .append(Global.breakTxtDownHTML(frsh, ((divwdth - 90 - wdth) / 7)) .replace(" ", " ")); } Global.strSB.append("</td>").append(System.getProperty("line.separator")); } if ((h % 2) == 1) { Global.strSB.append("</tr>").append(System.getProperty("line.separator")); } } } else if (grpColDvsns == 2) { for (int h = 0; h < colNumbers.length; h++) { Global.strSB.append("<tr>").append(System.getProperty("line.separator")); int clnm = -1; clnm = Integer.parseInt(colNumbers[h]); if (clnm >= 0) { String frsh = ""; Global.strSB.append( "<td style=\"border-bottom:none;border-left:none;font-weight:bold;\" align=\"" + algn + "\" width=\"" + wdth + "px\">") .append(System.getProperty("line.separator")); frsh = recsdtstmd.getColumnName(clnm + 1).trim() + ": "; Global.strSB.append( Global.breakTxtDownHTML(frsh, ((wdth) / 7)).replace(" ", " ")); Global.strSB.append("</td>").append(System.getProperty("line.separator")); Global.strSB .append("<td style=\"border-bottom:none;border-left:none;\" align=\"" + algn + "\" width=\"" + (divwdth - 90 - wdth) + "px\">") .append(System.getProperty("line.separator")); if (imgCols.contains("," + clnm + ",")) { frsh = recsdtst.getString(clnm + 1).trim(); File file = new File(Global.dataBasDir + frsh); // if file doesnt exists, then create it if (!file.exists()) { String extnsn = FilenameUtils.getExtension(Global.dataBasDir + frsh); Files.copy(new File(Global.dataBasDir + frsh).toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn).toPath(), StandardCopyOption.REPLACE_EXISTING); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn + "\" style=\"width:auto;height:" + grpMinHght + "px;\">" + "</p>") .append(System.getProperty("line.separator")); } } else { frsh = recsdtst.getString(clnm + 1).trim() + " "; Global.strSB .append(Global.breakTxtDownHTML(frsh, ((divwdth - 90 - wdth) / 7)) .replace(" ", " ")); } Global.strSB.append("</td>"); } Global.strSB.append("</tr>"); } } else if (grpColDvsns == 1) { for (int h = 0; h < colNumbers.length; h++) { Global.strSB.append("<tr>"); int clnm = -1; clnm = Integer.parseInt(colNumbers[h]); if (clnm >= 0) { String frsh = ""; Global.strSB .append("<td style=\"border-bottom:none;border-left:none;\" align=\"" + algn + "\" width=\"" + (divwdth - 90) + "px\">") .append(System.getProperty("line.separator")); if (imgCols.contains("," + clnm + ",")) { frsh = recsdtst.getString(clnm + 1).trim(); File file = new File(Global.dataBasDir + frsh); // if file doesnt exists, then create it if (!file.exists()) { String extnsn = FilenameUtils.getExtension(Global.dataBasDir + frsh); Files.copy(new File(Global.dataBasDir + frsh).toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn).toPath(), StandardCopyOption.REPLACE_EXISTING); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn + "\" style=\"width:auto;height:" + grpMinHght + "px;\">" + "</p>") .append(System.getProperty("line.separator")); } } else { frsh = recsdtst.getString(clnm + 1).trim() + " "; Global.strSB.append(Global.breakTxtDownHTML(frsh, ((divwdth - 90) / 7)) .replace(" ", " ")); } Global.strSB.append("</td>"); } Global.strSB.append("</tr>"); } } Global.strSB.append("</tbody></table>"); } else { } if (shwBrdr.equals("Show")) { Global.strSB.append("</fieldset>"); } Global.strSB.append("</div>"); } Global.strSB.append("</td></tr>"); Global.strSB.append("</tbody></table><br/><br/>").append(System.getProperty("line.separator")); } if (islast) { Global.strSB.append("</body></html>"); File file = new File(fileNm); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); bw.write(Global.strSB.toString()); bw.close(); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/amcharts_2100/samples/" + String.valueOf(Global.runID) + ".html"); } } } catch (IOException ex) { } catch (SQLException ex) { } catch (NumberFormatException ex) { } }
From source file:rems.Global.java
public static void exprtToHTMLSCC(ResultSet dtst, String fileNm, String rptTitle, String[] colsToGrp, String[] colsToUse, boolean isfirst, boolean islast, boolean shdAppnd) { try {// w w w . j a va 2s. c o m //Simple Column Chart dtst.last(); int totlRows = dtst.getRow(); dtst.beforeFirst(); ResultSetMetaData dtstmd = dtst.getMetaData(); int colCnt = dtstmd.getColumnCount(); String cption = ""; if (isfirst) { cption = "<caption align=\"top\">" + rptTitle + "</caption>"; Global.strSB.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"[]><html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-US\" xml:lang=\"en\"><head><meta http-equiv=\"Content-Type\" " + "content=\"text/html; charset=utf-8\">" + System.getProperty("line.separator") + "<title>" + rptTitle + "</title>" + System.getProperty("line.separator")); Global.strSB.append("<link rel=\"stylesheet\" href=\"../amcharts/rpt.css\" type=\"text/css\">" + System.getProperty("line.separator")); Global.strSB.append("<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">" + System.getProperty("line.separator")); Global.strSB.append("<script src=\"../amcharts/amcharts.js\" type=\"text/javascript\"></script>" + System.getProperty("line.separator")); Global.strSB.append("</head><body>"); Files.copy( new File(Global.getOrgImgsDrctry() + "/" + String.valueOf(Global.UsrsOrg_ID) + ".png") .toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.UsrsOrg_ID) + ".png").toPath(), StandardCopyOption.REPLACE_EXISTING); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/amcharts_2100/images/" + String.valueOf(Global.UsrsOrg_ID) + ".png"); } //Org Name String orgNm = Global.getOrgName(Global.UsrsOrg_ID); String pstl = Global.getOrgPstlAddrs(Global.UsrsOrg_ID); //Contacts Nos String cntcts = Global.getOrgContactNos(Global.UsrsOrg_ID); //Email Address String email = Global.getOrgEmailAddrs(Global.UsrsOrg_ID); Global.strSB.append("<p><img src=\"../images/" + String.valueOf(Global.UsrsOrg_ID) + ".png\">" + orgNm + "<br/>" + pstl + "<br/>" + cntcts + "<br/>" + email + "<br/>" + "</p>"); } Global.strSB.append("<script type = \"text / javascript\"> " + System.getProperty("line.separator") + "var chart;" + System.getProperty("line.separator") + "var chartData = ["); for (int a = 0; a < totlRows; a++) { dtst.next(); if (a < totlRows - 1) { Global.strSB.append( "{" + "ctgry:\"" + dtst.getString(Integer.parseInt(colsToUse[0]) + 1) + "\"," + "vals:" + dtst.getString(Integer.parseInt(colsToUse[1]) + 1) + ", color: \"#0D52D1\"},") .append(System.getProperty("line.separator")); } else { Global.strSB.append( "{" + "ctgry:\"" + dtst.getString(Integer.parseInt(colsToUse[0]) + 1) + "\"," + "vals:" + dtst.getString(Integer.parseInt(colsToUse[1]) + 1) + ", color:\"#0D52D1\"}];") .append(System.getProperty("line.separator")); } } Global.strSB.append("AmCharts.ready(function () {" + System.getProperty("line.separator") + "// SERIAL CHART " + System.getProperty("line.separator") + "chart = new AmCharts.AmSerialChart(); " + System.getProperty("line.separator") + "chart.dataProvider = chartData; " + System.getProperty("line.separator") + "chart.categoryField = \"ctgry\"; " + System.getProperty("line.separator") + "chart.depth3D = 0; " + System.getProperty("line.separator") + "chart.angle = 0; " + System.getProperty("line.separator") + "//chart.startDuration = 1;" + System.getProperty("line.separator") + "// AXES " + System.getProperty("line.separator") + "// category " + System.getProperty("line.separator") + "var categoryAxis = chart.categoryAxis; " + System.getProperty("line.separator") + "categoryAxis.labelRotation = 90; " + System.getProperty("line.separator") + "categoryAxis.title = \"" + dtstmd.getColumnName(Integer.parseInt(colsToUse[0]) + 1) + "\"; " + System.getProperty("line.separator") + "categoryAxis.gridPosition = \"start\";" + System.getProperty("line.separator") + "// value" + System.getProperty("line.separator") + "// in case you don't want to change default settings of value axis," + System.getProperty("line.separator") + "// you don't need to create it, as one value axis is created automatically. " + System.getProperty("line.separator") + "var valueAxis = new AmCharts.ValueAxis(); " + System.getProperty("line.separator") + "valueAxis.title = \"" + dtstmd.getColumnName(Integer.parseInt(colsToUse[1]) + 1) + "\"; " + System.getProperty("line.separator") + "valueAxis.dashLength = 5; " + System.getProperty("line.separator") + "chart.addValueAxis(valueAxis);" + System.getProperty("line.separator") + " // GRAPH " + System.getProperty("line.separator") + "var graph = new AmCharts.AmGraph(); " + System.getProperty("line.separator") + "graph.valueField = \"vals\"; " + System.getProperty("line.separator") + "graph.colorField = \"color\"; " + System.getProperty("line.separator") + "graph.balloonText = \"[[category]]: [[value]]\"; " + System.getProperty("line.separator") + "graph.type = \"column\"; " + System.getProperty("line.separator") + "graph.lineAlpha = 0; " + System.getProperty("line.separator") + "graph.fillAlphas = 1; " + System.getProperty("line.separator") + "chart.addGraph(graph);" + System.getProperty("line.separator") + "chart.write(\"chartdiv\");" + System.getProperty("line.separator") + "});" + System.getProperty("line.separator") + " </script>" + System.getProperty("line.separator")); Global.strSB.append("<h2>" + rptTitle + "</h2>").append(System.getProperty("line.separator")); Global.strSB.append("<div id=\"chartdiv\" style=\"width: " + colsToGrp[0] + "px; height: " + colsToGrp[1] + "px;\"></div>"); if (islast) { Global.strSB.append("</body></html>"); File file = new File(fileNm); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); bw.write(Global.strSB.length()); bw.close(); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/amcharts_2100/samples/" + String.valueOf(Global.runID) + ".html"); } } } catch (SQLException ex) { } catch (IOException ex) { } catch (NumberFormatException ex) { } }
From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java
/** * @param rsmd/*from w w w . ja v a2s .c o m*/ * @param map * @param tableNames * @throws SQLException */ protected void buildIndexMapFromMetaData(final ResultSetMetaData rsmd, final List<String> origList, final Hashtable<String, Integer> map) throws SQLException { map.clear(); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { sb.setLength(0); String tableName = rsmd.getTableName(i); String fieldName = rsmd.getColumnName(i); if (isNotEmpty(tableName)) { sb.append(tableName); } else { for (String fullName : origList) { String[] parts = split(fullName, "."); if (parts[1].equals(fieldName)) { sb.append(parts[0]); break; } } } sb.append("."); sb.append(fieldName); // log.info("["+strBuf.toString()+"] "+i); map.put(sb.toString(), i); } }
From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java
/** * @param tableName/*w w w . ja va 2 s . co m*/ */ protected void convertLocalityExtraInfo(final String tableName, final boolean isGeoCoordDetail) { removeForeignKeyConstraints(newDBConn, BasicSQLUtils.myDestinationServerType); String capName = capitalize(tableName); TableWriter tblWriter = convLogger.getWriter(capName + ".html", capName); setTblWriter(tblWriter); IdHashMapper.setTblWriter(tblWriter); setDesc("Converting " + capName); List<String> localityDetailNamesTmp = getFieldNamesFromSchema(newDBConn, tableName); List<String> localityDetailNames = new ArrayList<String>(); Hashtable<String, Boolean> nameHash = new Hashtable<String, Boolean>(); for (String fieldName : localityDetailNamesTmp) { localityDetailNames.add(fieldName); nameHash.put(fieldName, true); System.out.println("[" + fieldName + "]"); } String fieldList = buildSelectFieldList(localityDetailNames, null); log.info(fieldList); IdMapperIFace locIdMapper = idMapperMgr.get("locality", "LocalityID"); IdMapperIFace agtIdMapper = idMapperMgr.get("agent", "AgentID"); Statement updateStatement = null; try { updateStatement = newDBConn.createStatement(); Hashtable<String, Boolean> usedFieldHash = new Hashtable<String, Boolean>(); Statement stmt = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); Integer countRows = getCount( "select count(LocalityID) from locality,geography where locality.GeographyID = geography.GeographyID"); if (countRows != null) { frame.setProcess(0, countRows); } ResultSet rs = stmt.executeQuery( "select locality.*,geography.* from locality LEFT JOIN geography on locality.GeographyID = geography.GeographyID "); StringBuilder colSQL = new StringBuilder(); StringBuilder valuesSQL = new StringBuilder(); int rows = 0; while (rs.next()) { usedFieldHash.clear(); valuesSQL.setLength(0); boolean hasData = false; ResultSetMetaData metaData = rs.getMetaData(); int cols = metaData.getColumnCount(); for (int i = 1; i <= cols; i++) { String colName = metaData.getColumnName(i); // Old Column Name if (colName.equals("GeoRefDetBy")) { colName = "AgentID"; } if ((nameHash.get(colName) == null || usedFieldHash.get(colName) != null) && !colName.startsWith("Range")) { if (rows == 0) { log.debug("Skipping[" + colName + "]"); } continue; } usedFieldHash.put(colName, true); if (rows == 0) { System.err.println("[" + colName + "]"); if (colName.equals("Range")) { if (!isGeoCoordDetail) { if (colSQL.length() > 0) colSQL.append(","); colSQL.append("RangeDesc"); } } else if (isGeoCoordDetail) { if (!colName.equals("RangeDirection")) { if (colSQL.length() > 0) colSQL.append(","); colSQL.append(colName); } } else { if (colSQL.length() > 0) colSQL.append(","); colSQL.append(colName); } } String value; if (colName.equals("LocalityID")) { Integer oldId = rs.getInt(i); Integer newId = locIdMapper.get(oldId); if (newId != null) { value = Integer.toString(newId); } else { String msg = "Couldn't map LocalityId oldId[" + rs.getInt(i) + "]"; log.error(msg); tblWriter.logError(msg); value = "NULL"; } } else if (isGeoCoordDetail && colName.equals("GeoRefDetDate")) { Integer dateInt = rs.getInt(i); value = getStrValue(dateInt, "date"); } else if (colName.startsWith("YesNo")) { Integer bool = rs.getInt(i); if (bool == null) { value = "NULL"; } else if (bool == 0) { value = "0"; } else { value = "1"; } } else if (isGeoCoordDetail && colName.equals("AgentID")) { Integer agentID = (Integer) rs.getObject(i); if (agentID != null) { Integer newID = agtIdMapper.get(agentID); if (newID != null) { value = newID.toString(); } else { String msg = "Couldn't map GeoRefDetBY (Agent) oldId[" + agentID + "]"; log.error(msg); tblWriter.logError(msg); value = "NULL"; } } else { value = "NULL"; } } else if (colName.equals("Range") || colName.equals("RangeDirection")) { if (!isGeoCoordDetail) { String range = rs.getString(i); range = escapeStringLiterals(range); if (range != null) { hasData = true; value = "'" + range + "'"; } else { value = "NULL"; } } else { value = null; } } else { Object obj = rs.getObject(i); if (obj != null && !colName.equals("TimestampCreated") && !colName.equals("TimestampModified")) { hasData = true; } /*if (obj instanceof String) { String str = (String)obj; int inx = str.indexOf('\''); if (inx > -1) { obj = escapeStringLiterals(str); } }*/ value = getStrValue(obj); } // log.debug(colName+" ["+value+"]"); if (value != null) { if (valuesSQL.length() > 0) { valuesSQL.append(","); } valuesSQL.append(value); } } if (hasData) { String insertSQL = "INSERT INTO " + tableName + " (" + colSQL.toString() + ", Version, CreatedByAgentID, ModifiedByAgentID) " + " VALUES(" + valuesSQL.toString() + ", 0, " + getCreatorAgentId(null) + "," + getModifiedByAgentId(null) + ")"; /*if (true) { log.info(insertSQL); }*/ try { updateStatement.executeUpdate(insertSQL); updateStatement.clearBatch(); } catch (Exception ex) { System.out.println("isGeoCoordDetail: " + isGeoCoordDetail); System.out.println(insertSQL); ex.printStackTrace(); } } rows++; if (rows % 500 == 0) { frame.setProcess(rows); } } rs.close(); stmt.close(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { updateStatement.close(); } catch (SQLException ex) { ex.printStackTrace(); } } }
From source file:rems.Global.java
public static void exprtToHTMLLC(ResultSet dtst, String fileNm, String rptTitle, String[] colsToGrp, String[] colsToUse, boolean isfirst, boolean islast, boolean shdAppnd) { try {// w w w .j a v a2s . c om //Line Chart dtst.last(); int totlRows = dtst.getRow(); dtst.beforeFirst(); ResultSetMetaData dtstmd = dtst.getMetaData(); //int colCnt = dtstmd.getColumnCount(); int colCnt = colsToUse.length; String cption = ""; if (isfirst) { cption = "<caption align=\"top\">" + rptTitle + "</caption>"; Global.strSB.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"[]><html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-US\" xml:lang=\"en\"><head><meta http-equiv=\"Content-Type\" " + "content=\"text/html; charset=utf-8\"><title>" + rptTitle + "</title>") .append(System.getProperty("line.separator")) .append("<link rel=\"stylesheet\" href=\"../amcharts/rpt.css\" type=\"text/css\">") .append(System.getProperty("line.separator")); Global.strSB.append("<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">") .append(System.getProperty("line.separator")) .append("<script src = \"../amcharts / amcharts.js\" type = \"text / javascript\">") .append(System.getProperty("line.separator")).append("</script>") .append(System.getProperty("line.separator")); Global.strSB.append("</head><body>").append(System.getProperty("line.separator")); Files.copy( new File(Global.getOrgImgsDrctry() + "/" + String.valueOf(Global.UsrsOrg_ID) + ".png") .toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.UsrsOrg_ID) + ".png").toPath(), StandardCopyOption.REPLACE_EXISTING); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/amcharts_2100/images/" + String.valueOf(Global.UsrsOrg_ID) + ".png"); } //Org Name String orgNm = Global.getOrgName(Global.UsrsOrg_ID); String pstl = Global.getOrgPstlAddrs(Global.UsrsOrg_ID); //Contacts Nos String cntcts = Global.getOrgContactNos(Global.UsrsOrg_ID); //Email Address String email = Global.getOrgEmailAddrs(Global.UsrsOrg_ID); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.UsrsOrg_ID) + ".png\">" + orgNm + "<br/>" + pstl + "<br/>" + cntcts + "<br/>" + email + "<br/>" + "</p>") .append(System.getProperty("line.separator")); } Global.strSB.append("<script type=\"text/javascript\">").append(System.getProperty("line.separator")) .append("var chart;").append(System.getProperty("line.separator")).append("var chartData = [") .append(System.getProperty("line.separator")); for (int a = 0; a < totlRows; a++) { dtst.next(); if (a < totlRows - 1) { Global.strSB .append("{" + "ctgry:\"" + dtst.getString(Integer.parseInt(colsToUse[0]) + 1) + "\", " + "value: " + dtst.getString(Integer.parseInt(colsToUse[1]) + 1) + "},") .append(System.getProperty("line.separator")); } else { Global.strSB .append("{" + "ctgry:\"" + dtst.getString(Integer.parseInt(colsToUse[0]) + 1) + "\", " + "value:" + dtst.getString(Integer.parseInt(colsToUse[1]) + 1) + "}];") .append(System.getProperty("line.separator")); } } Global.strSB.append("AmCharts.ready(function () {").append(System.getProperty("line.separator")) .append("// SERIAL CHART").append(System.getProperty("line.separator")) .append("chart = new AmCharts.AmSerialChart();").append(System.getProperty("line.separator")) .append("chart.pathToImages = \"../amcharts/images/\";") .append(System.getProperty("line.separator")).append("chart.dataProvider = chartData;") .append(System.getProperty("line.separator")).append("chart.marginLeft = 10;") .append(System.getProperty("line.separator")).append("chart.categoryField = \"ctgry\";") .append(System.getProperty("line.separator")).append("chart.zoomOutButton = {") .append(System.getProperty("line.separator")).append("backgroundColor: '#000000',") .append("backgroundAlpha: 0.15};").append(System.getProperty("line.separator")) .append("// listen for dataUpdated event (fired when chart is inited) and call zoomChart method when it happens") .append(System.getProperty("line.separator")) .append("chart.addListener(\"dataUpdated\", zoomChart);") .append(System.getProperty("line.separator")).append("// AXES") .append(System.getProperty("line.separator")).append("// category") .append(System.getProperty("line.separator")).append("var categoryAxis = chart.categoryAxis;") .append(System.getProperty("line.separator")) .append("//categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true") .append(System.getProperty("line.separator")) .append("//categoryAxis.minPeriod = DD; // our data is ctgryly, so we set minPeriod to YYYY") .append(System.getProperty("line.separator")) .append("categoryAxis.title = \"" + dtstmd.getColumnName(Integer.parseInt(colsToUse[0]) + 1) + "\";") .append(System.getProperty("line.separator")).append("categoryAxis.gridAlpha = 0.5;") .append(System.getProperty("line.separator")).append("categoryAxis.labelRotation = 90;") .append(System.getProperty("line.separator")).append("// value") .append(System.getProperty("line.separator")) .append("var valueAxis = new AmCharts.ValueAxis();") .append(System.getProperty("line.separator")).append("valueAxis.axisAlpha = 0.5;") .append(System.getProperty("line.separator")) .append("valueAxis.title = \"" + dtstmd.getColumnName(Integer.parseInt(colsToUse[1]) + 1) + "\";") .append(System.getProperty("line.separator")).append("valueAxis.inside = true;") .append(System.getProperty("line.separator")).append("chart.addValueAxis(valueAxis);") .append(System.getProperty("line.separator")).append("// GRAPH ") .append(System.getProperty("line.separator")).append("graph = new AmCharts.AmGraph();") .append(System.getProperty("line.separator")) .append("graph.type = \"line\"; // this line makes the graph smoothed line.") .append(System.getProperty("line.separator")).append("graph.lineColor = \"#0000FF\";") .append(System.getProperty("line.separator")) .append("graph.negativeLineColor = \"#637bb6\"; // this line makes the graph to change color when it drops below 0") .append(System.getProperty("line.separator")).append("graph.bullet = \"round\";") .append(System.getProperty("line.separator")).append("graph.bulletSize = 5;") .append("graph.lineThickness = 1;").append(System.getProperty("line.separator")) .append("graph.valueField = \"value\";").append(System.getProperty("line.separator")) .append("chart.addGraph(graph);").append(System.getProperty("line.separator")) .append("// CURSOR ").append(System.getProperty("line.separator")) .append("var chartCursor = new AmCharts.ChartCursor();") .append(System.getProperty("line.separator")).append("chartCursor.cursorAlpha = 0;") .append(System.getProperty("line.separator")).append("chartCursor.cursorPosition = \"mouse\";") .append(System.getProperty("line.separator")) .append("//chartCursor.categoryBalloonDateFormat = \"YYYY\";") .append(System.getProperty("line.separator")).append("chart.addChartCursor(chartCursor);") .append(System.getProperty("line.separator")).append("// SCROLLBAR ") .append(System.getProperty("line.separator")) .append("var chartScrollbar = new AmCharts.ChartScrollbar();") .append(System.getProperty("line.separator")).append("chartScrollbar.graph = graph;") .append(System.getProperty("line.separator")) .append("chartScrollbar.backgroundColor = \"#DDDDDD\";") .append(System.getProperty("line.separator")).append("chartScrollbar.scrollbarHeight = 15;") .append(System.getProperty("line.separator")) .append("chartScrollbar.selectedBackgroundColor = \"#FFFFFF\";") .append(System.getProperty("line.separator")).append("chart.addChartScrollbar(chartScrollbar);") .append(System.getProperty("line.separator")).append("// WRITE") .append(System.getProperty("line.separator")).append("chart.write(\"chartdiv\");") .append(System.getProperty("line.separator")).append("});") .append(System.getProperty("line.separator")) .append("// this method is called when chart is first inited as we listen for \"dataUpdated\" event") .append(System.getProperty("line.separator")).append("function zoomChart() {") .append(System.getProperty("line.separator")) .append("// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues") .append(System.getProperty("line.separator")) .append("//chart.zoomToDates(new Date(1972, 0), new Date(1984, 0));") .append(System.getProperty("line.separator")).append("chart.zoomToIndexes(0,100);") .append(System.getProperty("line.separator")).append("}") .append(System.getProperty("line.separator")).append("</script>") .append(System.getProperty("line.separator")); Global.strSB.append("<h2>" + rptTitle + "</h2>").append(System.getProperty("line.separator")); Global.strSB.append("<div id=\"chartdiv\" style=\"width: " + colsToGrp[0] + "px; height: " + colsToGrp[1] + "px;\"></div>").append(System.getProperty("line.separator")); if (islast) { Global.strSB.append("</body></html>"); File file = new File(fileNm); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); bw.write(Global.strSB.toString()); bw.close(); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/amcharts_2100/samples/" + String.valueOf(Global.runID) + ".html"); } } } catch (SQLException ex) { } catch (IOException ex) { } catch (NumberFormatException ex) { } }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Initializes the given <code>RowSetMetaData</code> object with the values * in the given <code>ResultSetMetaData</code> object. * * @param md the <code>RowSetMetaData</code> object for this * <code>CachedRowSetImpl</code> object, which will be set with * values from rsmd// w w w .j a v a2 s. c o m * @param rsmd the <code>ResultSetMetaData</code> object from which new * values for md will be read * @throws SQLException if an error occurs */ private void initMetaData(RowSetMetaDataImpl md, ResultSetMetaData rsmd) throws SQLException { int numCols = rsmd.getColumnCount(); md.setColumnCount(numCols); for (int col = 1; col <= numCols; col++) { md.setAutoIncrement(col, rsmd.isAutoIncrement(col)); if (rsmd.isAutoIncrement(col)) updateOnInsert = true; md.setCaseSensitive(col, false); md.setCurrency(col, false); md.setNullable(col, rsmd.isNullable(col)); md.setSigned(col, rsmd.isSigned(col)); md.setSearchable(col, false); /* * The PostgreSQL drivers sometimes return negative columnDisplaySize, * which causes an exception to be thrown. Check for it. */ int size = rsmd.getColumnDisplaySize(col); if (size < 0) { size = 0; } md.setColumnDisplaySize(col, 0); if (StringUtils.isNotBlank(rsmd.getColumnLabel(col))) { md.setColumnLabel(col, rsmd.getColumnLabel(col).toLowerCase()); } if (StringUtils.isNotBlank(rsmd.getColumnName(col))) { md.setColumnName(col, rsmd.getColumnName(col).toLowerCase()); } md.setSchemaName(col, null); /* * Drivers return some strange values for precision, for non-numeric data, including reports of * non-integer values; maybe we should check type, & set to 0 for non-numeric types. */ int precision = rsmd.getPrecision(col); if (precision < 0) { precision = 0; } md.setPrecision(col, 0); /* * It seems, from a bug report, that a driver can sometimes return a negative * value for scale. javax.sql.rowset.RowSetMetaDataImpl will throw an exception * if we attempt to set a negative value. As such, we'll check for this case. */ int scale = rsmd.getScale(col); if (scale < 0) { scale = 0; } md.setScale(col, 0); md.setTableName(col, null); md.setCatalogName(col, null); md.setColumnType(col, -1); md.setColumnTypeName(col, null); } if (conn != null) { // JDBC 4.0 mandates as does the Java EE spec that all DataBaseMetaData methods // must be implemented, therefore, the previous fix for 5055528 is being backed out dbmslocatorsUpdateCopy = conn.getMetaData().locatorsUpdateCopy(); } }
From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java
/** * @param rsmd//from w w w . j a v a 2 s . c o m * @param map * @param tableNames * @throws SQLException */ protected void buildIndexMapFromMetaData(final ResultSetMetaData rsmd, final Hashtable<String, Integer> map, final String[] tableNames) throws SQLException { map.clear(); // Find the missing table name by figuring our which one isn't used. Hashtable<String, Boolean> existsMap = new Hashtable<String, Boolean>(); for (String tblName : tableNames) { existsMap.put(tblName, true); log.debug("[" + tblName + "]"); } for (int i = 1; i <= rsmd.getColumnCount(); i++) { String tableName = rsmd.getTableName(i); // log.info("["+tableName+"]"); if (isNotEmpty(tableName)) { if (existsMap.get(tableName) != null) { existsMap.remove(tableName); log.info("Removing Table Name[" + tableName + "]"); } } } String missingTableName = null; if (existsMap.size() == 1) { missingTableName = existsMap.keys().nextElement(); log.info("Missing Table Name[" + missingTableName + "]"); } else if (existsMap.size() > 1) { throw new RuntimeException("ExistsMap cannot have more than one name in it!"); } else { log.info("No Missing Table Names."); } for (int i = 1; i <= rsmd.getColumnCount(); i++) { strBuf.setLength(0); String tableName = rsmd.getTableName(i); strBuf.append(isNotEmpty(tableName) ? tableName : missingTableName); strBuf.append("."); strBuf.append(rsmd.getColumnName(i)); map.put(strBuf.toString(), i); } }