Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EDITABLE JTable and SQL QUERY

 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic