这个问题与我前面提到的THIS问题有关,这个问题解决了我的问题,但另一个问题出现了,我问自己'为什么会这样?'。
这是代码(BTW我在这个项目中使用了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
并且它工作正常但现在我不知道是什么问题或者我错过了什么?
答案 0 :(得分: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);
}