rows = 0; result = new Vector(); String s[] = new String[cols]; for (int i=1; i<=cols; i++) { s[i-1] = rsmd.getColumnLabel(i) ; }
result.addElement(s); rows ++; // for entire data while (rs.next()) { s = new String[cols]; // for one row for (int i=0; i<cols; i++) { s[i] = rs.getString(i+1); } result.addElement(s); rows ++; } return result; }
public int getColumnCount() { return cols; }
public int getRowCount() { return rows; }
public String getColumnLabels(int col) { String[] s = (String[])result.firstElement(); return s[col]; }
public String getCell(int col, int row) { String[] s = (String[])result.elementAt(row); return s[col]; } }
==============================
package ylb;
import java.sql.*;
import java.util.*;
import pubpkg.ExecDb;
public class mainBean {
private String xmlData;
int rows, cols;
Vector result;
//private ExecDb conn;
public Vector getData() throws Exception{
ExecDb conn = new ExecDb();
String tableStr = "";
String sql = "select * from a111a410_grid1";
ResultSet rs;
rs = conn.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
cols = rsmd.getColumnCount();
rows = 0;
result = new Vector();
String s[] = new String[cols];
for (int i=1; i<=cols; i++) {
s[i-1] = rsmd.getColumnLabel(i) ;
}
result.addElement(s);
rows ++;
// for entire data
while (rs.next()) {
s = new String[cols];
// for one row
for (int i=0; i<cols; i++) {
s[i] = rs.getString(i+1);
}
result.addElement(s);
rows ++;
}
return result;
}
public int getColumnCount() {
return cols;
}
public int getRowCount() {
return rows;
}
public String getColumnLabels(int col) {
String[] s = (String[])result.firstElement();
return s[col];
}
public String getCell(int col, int row) {
String[] s = (String[])result.elementAt(row);
return s[col];
}
}
test.jsp
==============================
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*"%>
<html>
<head>
<title></title>
<jsp:useBean id="myMainBean" scope="session" class="ylb.mainBean" />
<BODY leftmargin="1" topmargin="0">
<%!
int rows,cols;
Vector result;
%>
<%
result = myMainBean.getData();
rows = myMainBean.getRowCount();
cols = myMainBean.getColumnCount();
%>
<table width="100%" height="81" border="1" cellpadding="0" cellspacing="0" id=topTable>
<tr>
<td height="79" id=message>
</td>
</tr>
</table>
<TABLE class=sort-table id=mainTable cellSpacing=1 cellPadding=4 width="100%">
<THEAD>
<TR id="mainHead" align="middle">
<%
for(int i=0;i<cols;i++)
{
%>
<TD noWrap><%=myMainBean.getColumnLabels(i)%></TD>
<%
}
%>
</TR>
</THEAD>
<TBODY>
<%
for(int i=1;i<rows;i++)
{
%>
<TR>
<%
for(int j=0;j<cols;j++)
{
%>
<TD noWrap><%=myMainBean.getCell(j,i)%></TD>
<%
}
%>
</TR>
<%
}
%>
</TBODY>
</TABLE>
</body>
</html> 那这种是什么啊?