Advertisement
yayachadazt

terima sms

Sep 15th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. /*
  7. * NewJFrame2.java
  8. *
  9. * Created on Sep 13, 2014, 11:45:53 PM
  10. */
  11. package aplikasi.yaya.frame;
  12.  
  13. import aplikasi.yaya.koneksi.koneksi;
  14. import java.sql.SQLException;
  15. import javax.swing.JOptionPane;
  16.  
  17. /**
  18. *
  19. * @author AINUNJARIAH
  20. */
  21. public class NewJFrame2 extends javax.swing.JFrame {
  22. aplikasi.yaya.koneksi.koneksi konek = new koneksi();
  23. /** Creates new form NewJFrame2 */
  24. public NewJFrame2() {
  25. initComponents();
  26. konek.koneksi();
  27. }
  28.  
  29. /** This method is called from within the constructor to
  30. * initialize the form.
  31. * WARNING: Do NOT modify this code. The content of this method is
  32. * always regenerated by the Form Editor.
  33. */
  34. @SuppressWarnings("unchecked")
  35. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  36. private void initComponents() {
  37.  
  38. jButton1 = new javax.swing.JButton();
  39.  
  40. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  41.  
  42. jButton1.setText("jButton1");
  43. jButton1.addActionListener(new java.awt.event.ActionListener() {
  44. public void actionPerformed(java.awt.event.ActionEvent evt) {
  45. jButton1ActionPerformed(evt);
  46. }
  47. });
  48.  
  49. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  50. getContentPane().setLayout(layout);
  51. layout.setHorizontalGroup(
  52. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  53. .addGroup(layout.createSequentialGroup()
  54. .addGap(105, 105, 105)
  55. .addComponent(jButton1)
  56. .addContainerGap(222, Short.MAX_VALUE))
  57. );
  58. layout.setVerticalGroup(
  59. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  60. .addGroup(layout.createSequentialGroup()
  61. .addGap(88, 88, 88)
  62. .addComponent(jButton1)
  63. .addContainerGap(189, Short.MAX_VALUE))
  64. );
  65.  
  66. pack();
  67. }// </editor-fold>
  68.  
  69. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  70. try {
  71. // query untuk membaca SMS yang belum diproses
  72. String query = "SELECT * FROM inbox WHERE Processed ='false'";
  73. konek.res=konek.stat.executeQuery(query);
  74. while (konek.res.next())
  75. {
  76. // membaca ID SMS
  77. String id2 = konek.res.getString("ID");
  78. // membaca no pengirim
  79. String noPengirim = konek.res.getString("SenderNumber");
  80. // membaca pesan SMS dan mengubahnya menjadi kapital
  81. String msg = konek.res.getString("TextDecoded");
  82. // proses parsing
  83. // memecah pesan berdasarkan karakter <spasi>
  84. String []pecah = msg.split(" ");
  85. // jika kata terdepan dari SMS adalah 'saldo' maka cari saldo
  86. if ("saldo".equals(pecah[0]))
  87. {
  88. // baca idmasjid dari pesan SMS
  89. String idmasjid = pecah[1];
  90. // cari saldo berdasar idmasjid
  91. String query2 = "SELECT saldo FROM saldomasjid WHERE idmasjid ='"+idmasjid+"'";
  92. int hasil2=konek.stat.executeUpdate(query2);
  93. // cek bila data saldo tidak ditemukan
  94. if (hasil2==0) {
  95. String reply = "id masjid tidak ditemukan";
  96. }else{
  97. konek.res=konek.stat.executeQuery(query2);
  98. String saldo = konek.res.getString("saldo");
  99. String reply = "saldo Masjid Anda: "+saldo+"";
  100. }
  101. }
  102. else {
  103. String reply = "Maaf perintah salah, Cek FORMAT SMS ANDA : SALDO<spasi>ID MASJID";
  104.  
  105. // membuat SMS balasan
  106.  
  107. String query3 = "INSERT INTO outbox(DestinationNumber, TextDecoded,CreatorID) VALUES ('"+noPengirim+"', '"+reply+"','Gammu')";
  108. int hasil3 = konek.stat.executeUpdate(query3);
  109.  
  110. // ubah saldo 'processed' menjadi 'true' untuk setiap SMS yang telah diproses
  111.  
  112. String query4 = "UPDATE inbox SET Processed ='true' WHERE ID='"+id2+"'";
  113. int executeUpdate = konek.stat.executeUpdate(query4);
  114. }
  115.  
  116. }
  117. System.out.println("suksess");
  118. } catch (SQLException e) {
  119. System.out.println(e);
  120. }
  121. }
  122.  
  123. /**
  124. * @param args the command line arguments
  125. */
  126. public static void main(String args[]) {
  127. /* Set the Nimbus look and feel */
  128. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  129. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  130. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  131. */
  132. try {
  133. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  134. if ("Nimbus".equals(info.getName())) {
  135. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  136. break;
  137. }
  138. }
  139. } catch (ClassNotFoundException ex) {
  140. java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  141. } catch (InstantiationException ex) {
  142. java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  143. } catch (IllegalAccessException ex) {
  144. java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  145. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  146. java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  147. }
  148. //</editor-fold>
  149.  
  150. /* Create and display the form */
  151. java.awt.EventQueue.invokeLater(new Runnable() {
  152.  
  153. public void run() {
  154. new NewJFrame2().setVisible(true);
  155. }
  156. });
  157. }
  158. // Variables declaration - do not modify
  159. private javax.swing.JButton jButton1;
  160. // End of variables declaration
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement