Reputation: 89
I was having a problem with a project for school. The problem is that I acquired a code from school which I need to adjust to give the wanted criteria. The problem involves a database.
The program needs to get the current date+time when an action is performed (for practice I used a normal JButton), and it also needs to get the date+time when an action is performed on another button.
I need to modify this piece of code:
try {
stmt = conn.createStatement();
java.sql.Timestamp now = new Timestamp((new Date()).getTime());
PreparedStatement ps = conn.prepareStatement(
"INSERT INTO "Table name" (date_in, name, date_out, passcode)"+
" VALUES(?,?,?,null)" );
ps.setTimestamp(1, now);
ps.setString(2, "JavaTest");
Timestamp later = new Timestamp((new Date()).getTime());
ps.setTimestamp(3, later);
ps.executeUpdate();
The method needs to be paused after the ps.setString(2, "JavaTest");. After this part has been executed the method needs to pause and resume when another button has been pressed so there will be an entry in the database which has a different date_in and date_out.
I hope someone can help me cause I'm kind of stuck now.
Upvotes: 0
Views: 114
Reputation: 124
if I understand the problem correctly basically you have two buttons you want one to pause and the other to resume, every program runs in Java is running in a thread, even if you are not using multithreading, the main method runs in a thread called main, you need to pause this thread and resume it on the click of the other button, since it a school project I'm not going to tell you how to do it, you can read this and figure it out yourself :
http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html
look for wait() and notify()
Upvotes: 1