Advertisement
yayachadazt

tiap detik refresh

Sep 26th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. public void auto(){
  2. ActionListener taskPerformer = new ActionListener() {
  3.  
  4. public void actionPerformed(ActionEvent evt) {
  5. autosms();
  6. kirimotomatis(); /// isi methodnya ada dibawah
  7. }
  8. };
  9. new javax.swing.Timer(1000, taskPerformer).start();
  10.  
  11. }
  12.  
  13.  
  14. //// ini method ngmbil data dari database dan
  15. public void kirimotomatis(){
  16. try {
  17. java.util.Date skrg = new java.util.Date();
  18. java.text.SimpleDateFormat kal = new
  19. java.text.SimpleDateFormat("dd/MM/yyyy");
  20.  
  21. String tglsekarang=kal.format(skrg);
  22. // SET JAM
  23. Calendar cal=Calendar.getInstance();
  24. SimpleDateFormat jams=new SimpleDateFormat("HH:mm");
  25. String t=jams.format(cal.getTime());
  26. jLabel2.setText(t);
  27. try {
  28. String sql = "SELECT * FROM ustas WHERE proces ='false'";
  29. PreparedStatement pstat = con.prepareStatement(sql); // create a statement
  30. res=pstat.executeQuery();
  31. while (res.next())
  32. {
  33. String tglustas=res.getString("tanggal");
  34. String jamustas=res.getString("jam");
  35. String noustas=res.getString("nohp");
  36. String kett=res.getString("keterangan");
  37. String idustas=res.getString("id");
  38. try {
  39. if (tglsekarang.equals(tglustas)&&t.equals(jamustas)) {
  40. String query3 = "INSERT INTO outbox(DestinationNumber, TextDecoded,CreatorID) VALUES ('"+noustas+"', '"+kett+"','Gammu')";
  41. PreparedStatement hasil3=con.prepareStatement(query3);
  42. hasil3.executeUpdate();
  43. // ubah saldo 'processed' menjadi 'true' untuk setiap SMS yang telah diproses
  44.  
  45. String query4 = "UPDATE ustas SET proces ='true' WHERE ID='"+idustas+"'";
  46. PreparedStatement hasil4=con.prepareStatement(query4);
  47. hasil4.executeUpdate();
  48. }else{
  49.  
  50. }
  51. } catch (Exception e) {
  52. System.out.println("gtaot");
  53. }
  54.  
  55. }
  56. // System.out.println("suksess");
  57. } catch (SQLException e) {
  58. e.printStackTrace();
  59. }
  60. } catch (Exception e) {
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement