B
brownjenkn
Hi all,
I was hoping to get some advice/strategy on how best to do this. I
want to write a form to update a user's password on DB2 via a servlet.
The code below runs okay, and successfully updates a user password, but
I'd also like to verify it updated okay with a little dummy query at
the end. Having virtually no experience with threading, or the Runtime
class, etc. I think I need some help...
The idea behind the code below is to have the current thread sleep 5sec
which will give the external db2 process time to run and update the
password.
HERE'S MY CODE!
//----------------------------------------------------------
Runtime rt = Runtime.getRuntime();
rt.exec("db2cmd /c db2 connect to {someDatabase} user {someUser} using
{somePassword} new {newPassword} confirm {newPassword}")
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
/*
- code to connect to {someDatabase} and run a query to verify if update
was successful using whatever {newPassword} is
- if query runs okay, redirect to a "success" page, else display an
error message
*/
//----------------------------------------------------------
Question 1- is putting the current thread to sleep a good way to
handle this?
Question 2- should I use Thread.currentThread().sleep(5000) instead?
(ie. do it "non-statically")
Question 3- should I consider:
Process p = Runtime.getRuntime().exec("db2cmd /c db2 connect to
{someDatabase} user {someUser} using {somePassword} new {newPassword}
confirm {newPassword}");
p.waitFor();
instead of dealing with the Thread class? According to the API
waitFor() "causes the current thread to wait, if necessary, until the
process represented by this Process object has terminated."
Question 4- is there a totally better way to do this?
Any advice is much appreciated.
Thanks, Marc
I was hoping to get some advice/strategy on how best to do this. I
want to write a form to update a user's password on DB2 via a servlet.
The code below runs okay, and successfully updates a user password, but
I'd also like to verify it updated okay with a little dummy query at
the end. Having virtually no experience with threading, or the Runtime
class, etc. I think I need some help...
The idea behind the code below is to have the current thread sleep 5sec
which will give the external db2 process time to run and update the
password.
HERE'S MY CODE!
//----------------------------------------------------------
Runtime rt = Runtime.getRuntime();
rt.exec("db2cmd /c db2 connect to {someDatabase} user {someUser} using
{somePassword} new {newPassword} confirm {newPassword}")
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
/*
- code to connect to {someDatabase} and run a query to verify if update
was successful using whatever {newPassword} is
- if query runs okay, redirect to a "success" page, else display an
error message
*/
//----------------------------------------------------------
Question 1- is putting the current thread to sleep a good way to
handle this?
Question 2- should I use Thread.currentThread().sleep(5000) instead?
(ie. do it "non-statically")
Question 3- should I consider:
Process p = Runtime.getRuntime().exec("db2cmd /c db2 connect to
{someDatabase} user {someUser} using {somePassword} new {newPassword}
confirm {newPassword}");
p.waitFor();
instead of dealing with the Thread class? According to the API
waitFor() "causes the current thread to wait, if necessary, until the
process represented by this Process object has terminated."
Question 4- is there a totally better way to do this?
Any advice is much appreciated.
Thanks, Marc