public class TransactionsModel extends DefaultTableModel implements
ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JTable table;
int myColCount;
// JTextField txtfld;
// Constructor. This connects to the database retrieves
// data based on the stored procedure and populates the JTable in TransactionsView
TransactionsModel() {
}
TransactionsModel(JTextField accountnum) {
// myColCnt stores the columnCount.
int myColCnt = 0;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ResultSet rs = null;
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:odbc:oracle", "scott",
"tiger");
} catch (Exception ignored) {
System.out.println("Error in getting Connection");
ignored.printStackTrace();
}
try {
Statement stmt = con.createStatement();
rs = stmt
.executeQuery("SELECT * FROM TRANSACTIONS WHERE ACCOUNT_NO='"
+ accountnum.getText() + "'");
} catch (Exception ignored) {
}
try {
myColCnt = rs.getMetaData().getColumnCount();
} catch (SQLException sexcpt) {
System.out.println("Error in getting column count : "
+ sexcpt.getMessage());
}
try {
for (int i = 1; i <= myColCnt; i++)
{
// System.out.println("entered loop");
columnIdentifiers.addElement(rs.getMetaData().getColumnName(i));
// System.out.println("after colidentifiers");
}
} catch (Exception ignored) {
System.out.print("Exception caught");
ignored.printStackTrace();
}
Vector row = new Vector();
try {
while (rs.next()) {
row = new Vector();
for (int i = 1; i <= myColCnt; i++) {
row.addElement(rs.getObject(i));
}
dataVector.addElement(row);
}
}
catch (Exception ignored) {
}
}
public void actionPerformed(ActionEvent ae) {
}
}
~edit: code tags PB
*********************
this is the view class which has to display data OF THE JTable.the model is retriving the data but i am facing problem in displaying it. when i print the dataVector its is showing all the retrived values from the table in the DB.but how to display this data is wat that i am concerned about.
please help
thanks in advance...
harish.
This post has been edited by PennyBoki: 08 January 2008 - 11:03 AM

New Topic/Question
This topic is locked



MultiQuote









|