2

This one is related to THIS question which I asked before, this one kinda solve my problem but another problem came up and I'm asking myself 'why is that?'.

here is the codes (BTW I used r2xml.jar in this project) :

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));
}

Now here is my concern on the link that I gave, I can't make the TotalDue column data display on my JTable I dunno if it's because of the DATA TYPE that it has which is MONEY. but after using the codes above I manage to display it, but the problem now is that the other columns is now missing, non of them display on my column except TotalDue. Is there any explanation on that? is there a solution? I used this r2xml.jar before and it works fine but now I don't know what is the problem or am I missing something?

1 Answer 1

3

Then better go on the hard way, and this works as a charm.

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.