package com.fr.data; import java.sql.*; public class testDemo12 extends AbstractTableData { /** * 定义程序数据集的列名与数据保存位置 */ private String[] columnNames; private Object[][] rowData; /** * 实现构建函数,在构建函数中准备数据 */ public testDemo12() { String[] columnNames = {"pt_desc1", "pt_desc2", "pt_um", "ps_par", "ps_comp", "ps_ref", "ps_start", "ps_end", "ps_qty_per", "ps_scrp_pct", "pt_pm_code"}; Object[][] rowData = new String[1000][15]; String url = "jdbc:datadirect:openedge://xxx.xxx.xxx.xxx:xxx;databasename=mfgprod"; String user = "*****"; String password = "*****"; try { Class.forName("com.ddtek.jdbc.openedge.OpenEdgeDriver"); Connection connection = DriverManager.getConnection(url, user, password); String sql = "select pt_desc1,pt_desc2,pt_um,ps_par,ps_comp,ps_ref,ps_start,ps_end,ps_qty_per,ps_scrp_pct,pt_pm_code,case when pt_bom_code <> '' then pt_bom_code else pt_part end bom_code from pub.ps_mstr,pub.pt_mstr where ps_domain = 'TKL' and (ps_start <= curdate() or ps_start is null) and (ps_end >= curdate() or ps_end is null) and ps_ps_code = '' and pt_domain = ps_domain and pt_part = ps_comp and ps_par = ? with(nolock)"; PreparedStatement ps = connection.prepareStatement(sql); ps.setString(1, "TK-2960BW-1187-T"); ResultSet rs = ps.executeQuery(); int index = 0; while(rs.next()) { rowData[index][0] = rs.getString("pt_desc1"); rowData[index][1] = rs.getString("pt_desc2"); rowData[index][2] = rs.getString("pt_um"); rowData[index][3] = rs.getString("ps_par"); rowData[index][4] = rs.getString("ps_comp"); rowData[index][5] = rs.getString("ps_ref"); rowData[index][6] = rs.getString("ps_start"); rowData[index][7] = rs.getString("ps_end"); rowData[index][8] = rs.getDouble("ps_qty_per"); rowData[index][9] = rs.getDouble("ps_scrp_pct"); rowData[index][10] = rs.getString("pt_pm_code"); index++; } rs.close(); ps.close(); connection.close(); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); } this.columnNames = columnNames; this.rowData = rowData; } //实现ArrayTableData的其他四个方法,因为AbstractTableData已经实现了hasRow方法 @Override public int getColumnCount() { return columnNames.length; } @Override public String getColumnName(int columnIndex) { return columnNames[columnIndex]; } @Override public int getRowCount() { return rowData.length; } @Override public Object getValueAt(int rowIndex, int columnIndex) { return rowData[rowIndex][columnIndex]; } }