java


Timer Function Call in JFrameForm


Hello guys i want to run a class at hourly intervals in my JFrame Form..Ive read about using the Timer Task Class for this but im still not clear about how exactly to do this ...Id like suggestions on how to use a timer class to run the function below on hourly basis in the JFrame Form..Im using netbeans 8.2 and im coding in java.(im a newbie).
private void DisplayDailySum(){
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = " select sum(OverallTotal)as OverallTotal from invoices "
+ "where InvoiceDate between "
+ "'"+((JTextField)fromDate23.getDateEditor().getUiComponent()).getText()+"' "
+ "and '"+((JTextField)fromDate22.getDateEditor().getUiComponent()).getText()+"' and TransactionType='Cash' ";
rs = stmt.executeQuery(sql);
while(rs.next()){
c1=rs.getDouble("OverallTotal");
CashSum.setText(""+c1);
if(c1==0){
CashSum.setText(""+0.00);
}
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(this,"Unable to insert record "+e.getMessage());
}
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = " select sum(OverallTotal )as OverallTotal from invoices "
+ "where InvoiceDate between "
+ "'"+((JTextField)fromDate23.getDateEditor().getUiComponent()).getText()+"' "
+ "and '"+((JTextField)fromDate22.getDateEditor().getUiComponent()).getText()+"' and TransactionType='Cheque' ";
rs = stmt.executeQuery(sql);
while(rs.next()){
c2=rs.getDouble("OverallTotal");
ChequesSum.setText(""+c2);
if(c2==0){
ChequesSum.setText(""+0.00);
}
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(this,"Unable to insert record "+e.getMessage());
}
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = " select sum(OverallTotal ) as OverallTotal from invoices "
+ "where InvoiceDate between "
+ "'"+((JTextField)fromDate23.getDateEditor().getUiComponent()).getText()+"' "
+ "and '"+((JTextField)fromDate22.getDateEditor().getUiComponent()).getText()+"' and TransactionType='Credit' ";
rs = stmt.executeQuery(sql);
while(rs.next()){
c3=rs.getDouble("OverallTotal");
CreditSum.setText(""+c3);
if(c3==0){
CreditSum.setText(""+0.00);
}
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(this,"Unable to insert record "+e.getMessage());
}
sumL=c1+c2+c3;
sum=c1+c2;
DailySum.setText(""+sum);
}

Related Links

Is there a possibility to have a footer in a JScrollPane?
Context initialization fails when initializing bean that extends class inside jar
Keep a reference of JOptionPane returning an specific class
Load balancing strategy for data reading and writing cluster
Trouble making a jTable invisible
Cannot deserialize object with new readObject()/writeObject() methods
Method is undefined for the type. Help me fix it
Maven Multi Module Project Structuring Issues
Can I add to Combobox's model a different value than String?
java simple switch with enum
Problems with utf-8 on unix
How to benchmark the methods inside JUnit test?
Getting Sum of Column in Java Sqlite DB and Storing in Another Column
Loops With Multiple Variables
Do JSTL tags automatically escape HTML?
Validating two dates

Categories

HOME
yii2
client
omnet++
image-processing
activiti
mockito
objectgears
webstorm
programming-languages
react-redux
infragistics
jsrender
v8
gps
retrofit
fingerprint
ojdbc
ezpublish
azure-media-services
constraint-programming
slick-slider
gnupg
user-input
offline
export-to-csv
reactive-cocoa
undefined
contextmenu
viewport
visjs
errorlevel
csrf-protection
css-animations
sox
extjs5
language-agnostic
lcd
autosys
maquette
saas
msys2
large-file-upload
socialengine
cloud-code
code-search-engine
angularjs-factory
tasker
node-gyp
nxlog
acoustics
parentheses
termination
pubmed
paxos
veracode
carrot
forever
knockout-components
media-player
passport-google-oauth
slicknav
ado.net-entity-data-model
pickadate
pyke
netmq
google-places
wireshark-dissector
libressl
coveralls
ideamart
php-ci
mono-embedding
iiviewdeckcontroller
p2
formatjs
nsbutton
asp.net-web-api-odata
issuu
php-5.4
terminfo
xojo
openexr
android-radiobutton
tld
meteor-velocity
farseer
tidy
dataadapter
specification-pattern
jquery-knob
unc
trusted
google-email-migration
dsn
newtonscript
qtkit
nsobject
psi
xtype
appendto
imac
web-application-design
gamma
forums
avatar
3gp

Resources

Encrypt Message