craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > JDBC/Database Issues Post New Topic   Post A Reply
addUpdateSql() for bulk update printer friendly version
next newest post | next oldest post
Author Messages
khan379
Corporal

Gender: Male
Location:
Registered: Dec 2007
Status: Offline
Posts: 29

Click here to see the profile for khan379 Send email to khan379 Send private message to khan379 Find more posts by khan379 Edit or delete this message Reply w/Quote
Posted Monday, February 25, 2008 @ 16:30:30  

Hi again!
Everytime i come here i get a solution. thank you very much for taking time. my question for now is,

we have implemented drag and drop(or copy/paste) for 4 columns in our table. for example, if i copy(ctrl+C) a column cell value in first row, then go to the last row of the table and paste it in the same column. then all the rows for this column cell values will be assigned with the pasted value.
now the problem is, if i have update_on_row_exit, and have 4000 rows to update(believe me, we have to display as high as 50,000 rows!) then my addupdatesql is called called 4000 times. because of our so bad network to remote Database, this is taking verry long time.

Any idea regarding this kind of update will be helpful to me. like calling the addUpdateSql statement only once, to update all records in the database.

If the query is not clear. please let me know.
Thanks

--------------------
A H Khan

khan379
Corporal

Gender: Male
Location:
Registered: Dec 2007
Status: Offline
Posts: 29

Click here to see the profile for khan379 Send email to khan379 Send private message to khan379 Find more posts by khan379 Edit or delete this message Reply w/Quote
Posted Tuesday, February 26, 2008 @ 12:58:46  

to make it short, is there a way i can disable or not use addupdatesql method and call my own query to update the database?

Thanks,

--------------------
A H Khan

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Tuesday, February 26, 2008 @ 20:04:03  

You can use DatabaseChangeListener and implement beforeUpdate(int row) method and take care of the update yourself.

You can also turn off autocommit, and commit once all the records are updated, this should be faster.

dbTable.autoCommit = false;

If you want to handle the commit/rollback yourself, instead of quicktable handling it for you, set autoCommit to false. The default value for this property is true, quicktable itself handles the commit/rollback. when you want to handle the commit yourself, you can use getConnection() method and get the connection and then using connection.setAutoCommit(false/true) handle the connection. For commit/rollback use connection.commit()/connection.rollback

khan379
Corporal

Gender: Male
Location:
Registered: Dec 2007
Status: Offline
Posts: 29

Click here to see the profile for khan379 Send email to khan379 Send private message to khan379 Find more posts by khan379 Edit or delete this message Reply w/Quote
Posted Thursday, February 28, 2008 @ 13:00:15  

thank again!
i have implemented beforeUpdate(int row), and return false if i do bulk update and call my own update query. i did the querying using Oracle Update Batching.

now another question. :)
the same type of update can also be done with dbtable.doFindAndReplace functionality, by replace all. any idea how i can implement my own update query as i did above for only replace all using dbtable.doFindAndReplace. i dont care replace previous / replace next is done with my update query or addUpdateSql() method.

very Thanks,

[Edit by khan379 on Thursday, February 28, 2008 @ 13:00:40]

--------------------
A H Khan

khan379
Corporal

Gender: Male
Location:
Registered: Dec 2007
Status: Offline
Posts: 29

Click here to see the profile for khan379 Send email to khan379 Send private message to khan379 Find more posts by khan379 Edit or delete this message Reply w/Quote
Posted Friday, February 29, 2008 @ 11:14:35  

Looks like i can do this with replace and replaceAll methods od DBTable()..let me try.
I need to convert the Point returned by these methods to get the rows...
Thanks,

--------------------
A H Khan

khan379
Corporal

Gender: Male
Location:
Registered: Dec 2007
Status: Offline
Posts: 29

Click here to see the profile for khan379 Send email to khan379 Send private message to khan379 Find more posts by khan379 Edit or delete this message Reply w/Quote
Posted Friday, February 29, 2008 @ 13:37:09  

i cant get the logic for replaceAll in my case. replaceAll() replaces all occurrances of a string in my UI, if i return false for beforeUpdate(int row),
but how do i get to know the rows which got replaced??

Please help with any suggestion!!

Thanks,

--------------------
A H Khan

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Friday, February 29, 2008 @ 13:50:30  

The way you are doing is inefficient, use you database sql string functions and do the replace and just refresh the data in quicktable.
khan379
Corporal

Gender: Male
Location:
Registered: Dec 2007
Status: Offline
Posts: 29

Click here to see the profile for khan379 Send email to khan379 Send private message to khan379 Find more posts by khan379 Edit or delete this message Reply w/Quote
Posted Monday, March 3, 2008 @ 12:48:29  

thats the simpliest and great idea, i tried it and it works very quick for small table.

But as I said in previous posts, my table can be as big as 50,000 or 100,00 rows, and refreshing the UI will take lot more time.

if i use this approach and only say 100 rows needs to be updated for that condition, then refreshing the whole table is not a good idea....

any thoughts?

--------------------
A H Khan

khan379
Corporal

Gender: Male
Location:
Registered: Dec 2007
Status: Offline
Posts: 29

Click here to see the profile for khan379 Send email to khan379 Send private message to khan379 Find more posts by khan379 Edit or delete this message Reply w/Quote
Posted Tuesday, March 4, 2008 @ 14:47:53  

Please help whether this can be done or not, jsut one blocker for me now,
Let me explain what I am doing,
1. I call the dbTable.find() in a for loop and stores all the rows(p.x) in a Set collection.
2. then I call beforeUpdate(false) and dbTable.replaceAll()
3. then i call my update method that updates the rows that were found in first step.

this is working really fast except, when the occurance of the textToFind are continuous and more then one display page in the Table, then its highlighting the cell and aumatically scrolling for all the for loop values . this makes the process slower.

SO, is ther a way, I can stop this highlighting of cell ?
My code snippet is below,

Code:

E1.table.showFindReplaceMessages = false;
int i = 0;
while( i < E1.table.getRowCount() - 1 )
{
p = E1.table.find(p.x, p.y, textToFind.getText(), columnVector, true);
s.add(String.valueOf(p.x));
i = p.x ;
}
System.out.println("distinct rows changed : " + s);
FilterModel.massUpdate = true; //call to set beforeUpdate to false
E1.table.showFindReplaceMessages = true;
E1.table.replaceAll(0, 0, textToFind.getText(), replaceWith.getText(), columnVector);
replaceMass(); //method that does update to the databse
FilterModel.massUpdate = false; //call to set beforeUpdate to true

Thank you very much.

--------------------
A H Khan

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Wednesday, March 5, 2008 @ 22:47:44  

The best approach is to use some database stored procedure

1) which will using string functions to update all data.
2) Return the modified rows as resultset.
3) You go through the resultset and just update the database updated rows in Quicktable.

Return beforeUpdate as false, so that quicktable never tries to update them.

In your solution, I am not sure why you are trying to call find first.
I would just call replaceAll(), then when quicktable tries to update in database for each modified row , capture the updated row data and return false, so that quicktable does not update it. At the end of replace all, do batch update in database.

khan379
Corporal

Gender: Male
Location:
Registered: Dec 2007
Status: Offline
Posts: 29

Click here to see the profile for khan379 Send email to khan379 Send private message to khan379 Find more posts by khan379 Edit or delete this message Reply w/Quote
Posted Thursday, March 6, 2008 @ 11:02:52  

Exactly, i did the same yesterday. writing Stored procedure came to my mind but it is getting very complex in my case..
here is what i did for your info...i know this is not best solution as the number of rows increases.
Code:
for(int i = 0; i < E1.table.getRowCount(); i++)

{
for(int j = 0; j < FilterModel.edtCols.length; j++) // editable columns of the table
{
String s = (String) E1.table.getModel().getValueAt(i, FilterModel.edtCols[j]);
//if match is found, add the row to vector and break from inner for loop..
if (text1.indexOf(s) > -1)
{
rows.add(String.valueOf(i)); //rows is a vector
break;
}
}
}
E1.table.replaceAll(0, 0, text1, text2, columnVector);//this call replaces in UI
if (rows.size() > 0) //to make sure batch size is not zero
massReplace(); //this call replaces in the Database

Thanks you

--------------------
A H Khan

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios