📄 0172.htm
字号:
for (int i=0; i<aht_data.length; i++) <br>
{<br>
if (aht_data == null) <br>
{<br>
li_total_rows = i;<br>
break;<br>
}<br>
}<br>
<br>
// 2) rebuild a new hashtable array of the right size<br>
// and reload it with your data<br>
if (li_total_rows < aht_data.length) <br>
{ lht_temp = new Hashtable[li_total_rows];<br>
<br>
for (int i=0; i<li_total_rows; i++)<br>
{<br>
lht_temp[i] = aht_data[i];<br>
}<br>
<br>
aht_data = lht_temp;<br>
lht_temp = null;<br>
}<br>
<br>
return aht_data;<br>
}<br>
<br>
<br>
private Hashtable columnOrder(ResultSetMetaData ameta_data, int ai_columns)<br>
{ <br>
// 1) Size the Hashtable to be slighly larger than column count<br>
// and load factor to 1 so the hash table wont have to resize itself.<br>
Hashtable lht_row = new Hashtable((ai_columns + 3),1);<br>
<br>
try<br>
{ // 2) Store how many columns we have.<br>
lht_row.put("Column_Count",String.valueOf(ai_columns));<br>
<br>
// 3) Loop thru and store each column label and use its position<br>
// number as its key<br>
for ( int i = 1; i <= ai_columns; i++)<br>
{<br>
lht_row.put(String.valueOf(i),ameta_data.getColumnLabel(i));<br>
}<br>
}<br>
catch (SQLException e)<br>
{ // 4 Return a null result if an error happens<br>
lht_row = null;<br>
}<br>
<br>
return lht_row;<br>
} <br>
<br>
<br>
public String hastToTabFile(Hashtable[] ahash_data, boolean ab_header)<br>
{ //*****************************************************************<br>
// ahash_data: array of hashtables to convert to tabfile<br>
// ab_header : True if you want the tab file to include the headers<br>
//*****************************************************************<br>
String ls_tabfile = "";<br>
<br>
if (ahash_data == null)<br>
{ // 1) if no data then return empty file<br>
ls_tabfile = "";<br>
}<br>
else<br>
{<br>
// 2) first get column headers<br>
int li_column_count = 0;<br>
String ls_column_count = ahash_data[0].get("Column_Count").toString();<br>
try<br>
{<br>
li_column_count = Integer.parseInt(ls_column_count);<br>
}<br>
catch(NumberFormatException e)<br>
{ <br>
// 3) since this hashtable doesnt have the the column data stashed<br>
// treat it as a normal hashtable array <br>
return hashToTab(ahash_data,ab_header);<br>
}<br>
<br>
<br>
// 4) Gather up each columns label/key name also build up the header column<br>
String[] ls_indexes = new String[li_column_count];<br>
<br>
for(int icol = 0; icol < li_column_count; icol++)<br>
{<br>
ls_indexes[icol] = ahash_data[0].get(String.valueOf(icol+1)).toString();<br>
if(ab_header) ls_tabfile = ls_tabfile + ls_indexes[icol] + "\t";<br>
}<br>
<br>
<br>
// 5) Include the headers in the file if user requested them<br>
if(ab_header) ls_tabfile = ls_tabfile + "\n";<br>
<br>
<br>
// 6) loop through and gather tha data to display<br>
for (int irow=1; irow < ahash_data.length; irow++)<br>
{ if (ahash_data[irow] != null)<br>
{<br>
for(int icol = 0; icol < li_column_count; icol++)<br>
{<br>
ls_tabfile = ls_tabfile + ahash_data[irow].get(ls_indexes[icol]).toString() + "\t";<br>
} <br>
ls_tabfile = ls_tabfile + "\n";<br>
}<br>
}<br>
}<br>
<br>
return ls_tabfile;<br>
}<br>
<br>
<br>
private String hashToTab(Hashtable[] ahash_data, boolean ab_header)<br>
{//*****************************************************************<br>
// ahash_data: array of hashtables to convert to tabfile<br>
// ab_header : True if you want the tab file to include the headers<br>
//*****************************************************************<br>
String ls_tabfile = "";<br>
<br>
if (ahash_data == null)<br>
{ // 1) if no data return empty file<br>
ls_tabfile = "";<br>
}<br>
else<br>
{<br>
// 2) IF requested print out the header files<br>
if (ab_header)<br>
{<br>
for(Enumeration lenum_header = ahash_data[0].keys(); lenum_header.hasMoreElements();)<br>
{<br>
String ls_col = lenum_header.nextElement().toString() + "\t";<br>
ls_tabfile = ls_tabfile + ls_col;<br>
} <br>
ls_tabfile = ls_tabfile + "\n";<br>
}<br>
<br>
// 3) Loop through the rows and gather tha data to display<br>
for (int i=0; i < ahash_data.length; i++)<br>
{ Hashtable lhash_row = ahash_data[i];<br>
if (lhash_row != null)<br>
{ // 4) Loop thru each column and prints the columns data<br>
for(Enumeration l_enum = lhash_row.keys(); l_enum.hasMoreElements();)<br>
{<br>
String ls_col = l_enum.nextElement().toString() ;<br>
ls_tabfile = ls_tabfile + lhash_row.get(ls_col).toString() + "\t";<br>
} <br>
ls_tabfile = ls_tabfile + "\n";<br>
}<br>
}<br>
}<br>
<br>
return ls_tabfile;<br>
}
</table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -