Advertisement
yayachadazt

auto reply

Sep 18th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. try {
  2. // query untuk membaca SMS yang belum diproses
  3. String sql = "SELECT * FROM inbox WHERE Processed ='false'";
  4. PreparedStatement pstat = con.prepareStatement(sql); // create a statement
  5. res=pstat.executeQuery();
  6. while (res.next())
  7. {
  8. // membaca ID SMS
  9. String id2 = res.getString("ID");
  10. // membaca no pengirim
  11. String noPengirim = res.getString("SenderNumber");
  12. // membaca pesan SMS dan mengubahnya menjadi kapital
  13. String msg1 = res.getString("TextDecoded");
  14. String msg=msg1.toUpperCase();
  15. // proses parsing
  16. // memecah pesan berdasarkan karakter <spasi>
  17. String []pecah = msg.split(" ");
  18. // jika kata terdepan dari SMS adalah 'saldo' maka cari saldo
  19. try {
  20. if ("CEK".equals(pecah[0])&&"SALDO".equals(pecah[1]))
  21. {
  22.  
  23. String query2 = "SELECT * FROM saldomasjid WHERE idmasjid ='12345'";
  24. PreparedStatement hasil2=con.prepareStatement(query2);
  25. res=hasil2.executeQuery();
  26. while (res.next()) {
  27. int saldo=res.getInt("saldo");
  28.  
  29. DecimalFormat df = (DecimalFormat) DecimalFormat.getCurrencyInstance();
  30. DecimalFormatSymbols dfs = new DecimalFormatSymbols();
  31. dfs.setCurrencySymbol("");
  32. dfs.setMonetaryDecimalSeparator(',');
  33. dfs.setGroupingSeparator('.');
  34. df.setDecimalFormatSymbols(dfs);
  35. String hsl = "Rp. " + df.format(saldo);
  36. System.out.println(hsl);
  37. String reply = "Jumlah Saldo Masjid Adalah "+hsl+"";
  38. System.out.println(msg);
  39. String query3 = "INSERT INTO outbox(DestinationNumber, TextDecoded,CreatorID) VALUES ('"+noPengirim+"', '"+reply+"','Gammu')";
  40. PreparedStatement hasil3=con.prepareStatement(query3);
  41. hasil3.executeUpdate();
  42. // ubah saldo 'processed' menjadi 'true' untuk setiap SMS yang telah diproses
  43.  
  44. String query4 = "UPDATE inbox SET Processed ='true' WHERE ID='"+id2+"'";
  45. PreparedStatement hasil4=con.prepareStatement(query4);
  46. hasil4.executeUpdate();
  47. }
  48.  
  49.  
  50.  
  51.  
  52. }else {
  53. String reply = "Maaf perintah salah, Cek FORMAT SMS ANDA : SALDO<spasi>ID MASJID";
  54.  
  55. // membuat SMS balasan
  56.  
  57. String query3 = "INSERT INTO outbox(DestinationNumber, TextDecoded,CreatorID) VALUES ('"+noPengirim+"', '"+reply+"','Gammu')";
  58. PreparedStatement hasil3=con.prepareStatement(query3);
  59. hasil3.executeUpdate();
  60. // ubah saldo 'processed' menjadi 'true' untuk setiap SMS yang telah diproses
  61.  
  62. String query4 = "UPDATE inbox SET Processed ='true' WHERE ID='"+id2+"'";
  63. PreparedStatement hasil4=con.prepareStatement(query4);
  64. hasil4.executeUpdate();
  65. }
  66. } catch (Exception e) {
  67. System.out.println("eor");
  68. }
  69.  
  70. }
  71. System.out.println("suksess");
  72. } catch (SQLException e) {
  73. e.printStackTrace();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement