aspose file tools*
The moose likes JDBC and the fly likes Its Very Urgent !!!! Help Me Now !!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Its Very Urgent !!!! Help Me Now !!!!!! " Watch "Its Very Urgent !!!! Help Me Now !!!!!! " New topic
Author

Its Very Urgent !!!! Help Me Now !!!!!!

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
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

a schema is not needed to get the primary keys from the connection. Have a look at the DatabaseMetaData's getPrimaryKeys() function.
from the java.sql.DatabaseMetaData docs:
getPrimaryKeys
Parameters:
catalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteria
schema - a schema name; "" retrieves those without a schema
table - a table name

instead of specifying the Schema name, just use empty strings to indicate it does not have a schema
Jamie
[ April 21, 2003: Message edited by: Jamie Robertson ]
Anurag Mishra
Ranch Hand

Joined: Sep 27, 2001
Posts: 133
Dear Jamie Robertson,
Can you please tell me in detail, what i have to do to eliminate a lock from this code. Kindly write a line of code as an example for me, I will really help me a lot.
Anu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Its Very Urgent !!!! Help Me Now !!!!!!
 
Similar Threads
SQL exception
JTable
jtable
JTable
EDITABLE JTable and SQL QUERY