Wow, very cool.
What I did was go into the properties of the empty JTable and clicked on 'Customize Code.' Then in the second dropbox on the left I chose 'custom property', where I pasted the stuff in there over what was already there. That's what I'm supposed to do, right?
Here were a couple other quick questions I had:
1) You start out the code with 'Object', but what was originally there said 'new Object.' Should I do it like that, or just leave it as Object.
2) At the end of the line that reads:
String Query = "select ID, FIRST, LAST from table where variable = 'Y";;
You put two semicolons. Should there be just one, or two?
3) When I try to run the project to test it out, it says:
Class "myproject.TableTest" does not have a main method.
How would I fix that so it will run?
Thanks so much for your help!
Mark
Also, it won't let me run the program as it says
Main Topics
Browse All Topics





by: NelliosPosted on 2008-01-30 at 01:53:27ID: 20775824
If you are using matisse there are a couple of nice tutorials you can use: /60/java/g ui-db.html
tement().e xecuteQuer y(Query);
ut); ableModel(
http://www.netbeans.org/kb
The one above is using persistence. If you do not wish to use Persistence and just use the JDBC driver you can go like this:
/*Assuming your JTABLE is called myTable*/
Object[][] Data = null;
try {
String Query = "select ID, FIRST, LAST from table where variable = 'Y";;
ResultSet rs = myJDBCConnection.createSta
rs.last();
int Size = rs.getRow();
rs.first();
if (netSize > 0) {
Data = new Object[Size][3];
for (int j = 0; j < Size; j++) {
Data[j][0] = rs.getString("ID");
Data[j][1] = rs.getString("First");
Data[j][1] = rs.getString("Last");
rs.next();
}
}
}
catch (Exception e) {
e.printStackTrace(System.o
}
mytable.setModel(new javax.swing.table.DefaultT
Data,
new String[] {
"ID", "First", "Last" }
) {
Class[] types = new Class[] {
java.lang.String.class, java.lang.String.class, java.lang.String.class};
boolean[] canEdit = new boolean[] {
false, false, false
};
public Class getColumnClass(int columnIndex) {
return types[columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
Hope this helps