This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes EDITABLE JTable and SQL QUERY Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "EDITABLE JTable and SQL QUERY " Watch "EDITABLE JTable and SQL QUERY " New topic
Author

EDITABLE JTable and SQL QUERY

Anurag Mishra
Ranch Hand

Joined: Sep 27, 2001
Posts: 133
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
 
GeeCON Prague 2014
 
subject: EDITABLE JTable and SQL QUERY