• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EDITABLE JTable and SQL QUERY

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ello,
Can anybody help me, I am in a great toruble, Here in this example the comment part i.e.(//) this part they have mentioned that due to absence of database schema..the everything is locked. I want to know that how to open a lock so that I can able to edit the contents of the Cell. Please help me, what all changes I have to make to open a lock. For more reference: This is a Table Example of JDK1.3. or higher. I had taken out this code from:
D:\j2sdk1.4.0\demo\jfc\TableExample\src
The files are:
1) JDBCAdapter (For database connectivity)
2) TableMap (Defines underlying data structure of JTable)
3) TableSorter (For sorting)
5) Table Example (Main Class)
public void setValueAt(Object value, int row, int column) {
try {
String tableName = metaData.getTableName(column+1);
// Some of the drivers seem buggy, tableName should not be null.
if (tableName == null) {
System.out.println("Table name returned null.");
}
String columnName = getColumnName(column);
String query =
"update "+tableName+
" set "+columnName+" = "+dbRepresentation(column, value)+
" where ";
// We don't have a model of the schema so we don't know the
// primary keys or which columns to lock on. To demonstrate
// that editing is possible, we'll just lock on everything.
for(int col = 0; col<getColumnCount(); col++) {
String colName = getColumnName(col);
if (colName.equals("")) {
continue;
}
if (col != 0) {
query = query + " and ";
}
query = query + colName +" = "+
dbRepresentation(col, getValueAt(row, col));
}
System.out.println(query);
System.out.println("Not sending update to database");
// statement.executeQuery(query);
}
catch (SQLException e) {
// e.printStackTrace();
System.err.println("Update failed");
}
Vector dataRow = (Vector)rows.elementAt(row);
dataRow.setElementAt(value, column);
}
}
I want to use this code in one of my project. Please help me, I will be really very thankful to you. And if you are having any of the source code through which my need can be fulfilled, please give it to me i will be really thankful to you. Actually my need is,
When I pass some ID to the database (SQL) it give results in JTable, and that results can be edited i.e. (Adding of rows, Deleting of rows, Changing values of Cells etc.) If anybody is having such kind of code or any weblink please let me know. It is a request to all java developers.

Thanks
Anu
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic