2

这个问题与我之前问过的这个问题有关,这个问题有点解决了我的问题,但又出现了另一个问题,我问自己“为什么会这样?”。

这是代码(顺便说一句我r2xml.jar在这个项目中使用):

private void search() throws Exception{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url = "jdbc:odbc:*****";
    String user = "*****";
    String pass = "*****";
    Connection conn =  DriverManager.getConnection(url, user, pass);
    PreparedStatement ps;   
    ResultSet rs;
    String custname = "SELECT pIDNo AS 'Patient ID',pLName AS 'Last Name', pFName AS 'First Name',pMI AS 'M.I.',pSex AS 'Sex',pStatus AS 'Status', pTelNo AS 'Contact No.', pDocID AS 'Doctor ID', pAddr AS 'St. No.',pStreet AS 'St. Name',pBarangay AS 'Barangay',pCity AS 'City', pProvince AS 'Province', pLNameKIN AS 'Last Name',pFNameKIN AS 'First Name',pMIKIN AS 'M.I.',pRelationKIN AS 'Relation',pTotalDue AS 'Total Due' FROM dbo.Patients where pIDNo LIKE '" + "%'";
    ps = conn.prepareStatement(custname);
    rs = ps.executeQuery();
    tblPatient.setModel(DbUtils.resultSetToTableModel(rs));
}

现在这是我对我提供的链接的关注,我无法让TotalDue列数据显示在我JTable不知道是否是因为DATA TYPE它具有MONEY. 但是在使用上面的代码之后,我设法显示它,但现在的问题是其他列现在丢失了,除了TotalDue. 对此有什么解释吗?有解决办法吗?我r2xml.jar以前用过它,它工作正常,但现在我不知道是什么问题,或者我错过了什么?

4

1 回答 1

3

然后最好继续努力,这是一种魅力。

DefaultTableModel tbl = (DefaultTableModel) tblPatient.getModel();
ResultSetMetaData rm = rs.getMetaData(); // this line is useless if you know the column count. (I was too lazy to count :P )
int size = rm.getColumnCount();

while(rs.next()){
  Object[] obj = new Object[size];
  for(int i=0;i<size;i++){
    obj[i] = rs.getObject(i+1);
  }
  tbl.addRow(obj);
}
于 2013-04-12T09:59:38.050 回答