How to display details in database in frame using JTable??? please help?
-
my code is : private void displayPrisoners() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDri… Connection conn = DriverManager.getConnection("jdbc:odbc:P… Statement state=conn.createStatement(); String sql="Select * from Prisoner"; ResultSet rs=state.executeQuery(sql); FillTable model = new FillTable(rs); tblPrisoners=new JTable(model); rs.close(); state.close(); conn.close(); } catch(Exception e) { System.out.print(e.toString()); } but i don't know how to display the data in a Table.
-
Answer:
YAH. I GOT UR QUES. HERE U NEED TO CREATE A PACKAGE OF ABSTRACTTABLEMODEL AND THEN IMPORT IT TO THE MAIN CLASS TO BE USED O DIPLAY THE DETAILS. THE PACKAGE CCAN BE CEATED AS: public class FillTable extends AbstractTableModel{ private Vector<String[]> RowData=new Vector<String[]>(); private String[] columns=new String[0]; public FillTable() { try{ setResultset(_rs); } catch(Exception e){ System.out.print(e.toString()); } } public void setResultset( results) { try { ResultSetMetaData metaDt=results.getMetaData(); int cols=metaDt.getColumnCount(); columns=new String[cols]; for(int i=0;i<cols;i++) { columns[i]=metaDt.getColumnLabel(i+1); } String[] rowData; while(next()) { rowData=new String[cols]; for(int i=0;i<cols;i++) { rowData[i]=results.getString(i+1); } RowData.addElement(rowData); } fireTableChanged(null); } catch(Exception e) { } } public int getRowCount() { return RowData==null?0:RowData.size(); } public int getColumnCount() { return columns.length; } public String getValueAt(int rowIndex, int columnIndex) { return RowData.elementAt(rowIndex)[columnIndex]… } public String getColumnName(int col) { return columns[col]==null?" } } AFTER THIS YOU CAN IMPORT IT TO THE DISPLAY CLASS.
RUNJHUN at Yahoo! Answers Visit the source
Related Q & A:
- How to display Android database data in a ListView?Best solution by Stack Overflow
- How to display HTML data from database?Best solution by Stack Overflow
- how can I listen for database changes using java?Best solution by Stack Overflow
- How to Display an Image in PDF, which is retrieved from MySql Database :JSP and iText?Best solution by Stack Overflow
- Why cant i view my contacts display image? please help if you know ,thanks?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.