getColumnName方法获取不了列名
publicclassTableModeZhangHuextendsAbstractTableModel{String[]title={"账单编号","商品名称","商品...
public class TableModeZhangHu extends AbstractTableModel{ String[] title={"账单编号","商品名称","商品数量","交易单位","交易金额","是否付款","供应商编号","供应商名称","商品描述","账单时间"}; Object[][] rows=null; public TableModeZhangHu(){ UserService userService=new UserServiceImpl(); try { ArrayList<AccountBean> list=userService.queryAllzhanghu(); rows=new Object[list.size()][title.length]; int i=0; for (AccountBean accountBean : list) { rows[i][0]=accountBean.getA_id(); rows[i][1]=accountBean.getA_name(); rows[i][2]=accountBean.getA_nums(); rows[i][3]=accountBean.getA_amount(); rows[i][4]=accountBean.getA_unit(); rows[i][5]=accountBean.getA_ispayed(); rows[i][6]=accountBean.getS_id(); rows[i][7]=accountBean.getS_name(); rows[i][8]=accountBean.getA_Info(); rows[i][9]=accountBean.getA_Date(); i++; } } catch (BlogException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public String getColumnName(int column){ return title[column]; } @Override public int getRowCount() { // TODO Auto-generated method stub return rows.length; } @Override public int getColumnCount() { // TODO Auto-generated method stub return title.length; } @Override public Object getValueAt(int rowIndex, int columnIndex) { // TODO Auto-generated method stub return rows[rowIndex][columnIndex]; } }
展开
1个回答
展开全部
可以用下面的方式获取,把tableName换成你的表名,有些数据库也可以直接使用Sql查询表列名
ResultSet resultSet = statement.executeQuery("select * from tableName");
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
for(int i=0; i<resultSetMetaData.getColumnCount(); i++) {
System.out.print( resultSetMetaData.getColumnLabel(i) + "\t" );
System.out.print( resultSetMetaData.getColumnName(i) + "\t" );
System.out.println( resultSetMetaData.getColumnTypeName(i) );
}
ResultSet resultSet = statement.executeQuery("select * from tableName");
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
for(int i=0; i<resultSetMetaData.getColumnCount(); i++) {
System.out.print( resultSetMetaData.getColumnLabel(i) + "\t" );
System.out.print( resultSetMetaData.getColumnName(i) + "\t" );
System.out.println( resultSetMetaData.getColumnTypeName(i) );
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询