Guest User

Untitled

a guest
Jan 12th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. Data is not inserting into mysql database [closed]
  2. private static String destination;
  3.  
  4. public static void main(String[] args) {
  5. ArrayList data = new ArrayList();
  6. String str = "9035";
  7. int cost = 0;
  8. String AreaCode = null;
  9. int Rate = 0;
  10. int dur = 0;
  11. String calldate = null;
  12. String clid = null;
  13. String src = null;
  14. String dst = null;
  15. String dcontext = null;
  16. String channel = null;
  17. String dstchannel = null;
  18. String lastapp = null;
  19. String duration = null;
  20. String lastdata = null;
  21. String billsec = null;
  22. String disposition = null;
  23. String amaflags = null;
  24. String accountcode = null;
  25. String uniqueid = null;
  26. String userfield = null;
  27. try {
  28. Connection con = null;
  29. Class.forName("com.mysql.jdbc.Driver");
  30. con = DriverManager.getConnection(
  31. "jdbc:mysql://localhost:3306/asteriskcdrdb", "root", "techsoft");
  32. Statement st = con.createStatement();
  33. ResultSet rs = st.executeQuery("Select * from asteriskcdrdb.sp1 where areacode = '" + str + "'");
  34.  
  35. while (rs.next()) {
  36. AreaCode = rs.getString("AreaCode");
  37. //System.out.println(AreaCode);
  38. String Pulse = rs.getString("Pulse");
  39. Rate = rs.getInt("Rate/pulse");
  40. // System.out.println(Rate);
  41. }
  42. rs.close();
  43. st.close();
  44. } catch (Exception e) {
  45. System.out.println(e);
  46.  
  47.  
  48. }
  49. if (AreaCode.equals(str)) {
  50. //System.out.println("Hii");
  51. try {
  52. Connection conn = null;
  53. Class.forName("com.mysql.jdbc.Driver");
  54. conn = DriverManager.getConnection(
  55. "jdbc:mysql://localhost:3306/asteriskcdrdb", "root", "techsoft");
  56. Statement stmt = conn.createStatement();
  57. ResultSet rst = stmt.executeQuery("Select * from cdr where src ='9035020090'");
  58.  
  59. while (rst.next()) {
  60.  
  61.  
  62. while (rst.next()) {
  63. calldate = rst.getString("calldate");
  64.  
  65. //System.out.println(calldate);
  66. clid = rst.getString("clid");
  67. src = rst.getString("src");
  68. dst = rst.getString("dst");
  69. dcontext = rst.getString("dcontext");
  70. channel = rst.getString("channel");
  71. dstchannel = rst.getString("dstchannel");
  72. lastapp = rst.getString("lastapp");
  73. lastdata = rst.getString("lastdata");
  74. duration = rst.getString("duration");
  75. // System.out.println(duration);
  76. dur = Integer.parseInt(duration);
  77. data.add(dur);
  78. //System.out.println(dur);
  79. billsec = rst.getString("billsec");
  80. disposition = rst.getString("disposition");
  81. amaflags = rst.getString("amaflags");
  82. accountcode = rst.getString("accountcode");
  83. uniqueid = rst.getString("uniqueid");
  84. userfield = rst.getString("userfield");
  85. }
  86. }
  87. } catch (Exception e) {
  88. System.out.println(e);
  89. }
  90. }
  91.  
  92. for (int i = 0; i < data.size(); i++) {
  93. System.out.println(data);
  94. int c=(int) data.get(i);
  95. System.out.println(c);
  96. int min = 60;
  97. // System.out.println(dur);
  98. int quotient = c / min;
  99. // System.out.println(quotient);
  100.  
  101. int reminder =c % min;
  102. // System.out.println(reminder);
  103.  
  104. if (reminder > 0) {
  105. quotient = quotient + 1;
  106. System.out.println(quotient);
  107. cost = quotient * Rate;
  108. System.out.println(cost);
  109.  
  110. try {
  111. Connection conn = null;
  112. Class.forName("com.mysql.jdbc.Driver");
  113. conn = DriverManager.getConnection(
  114. "jdbc:mysql://localhost:3306/asteriskcdrdb", "root",
  115. "techsoft");
  116.  
  117. Statement stmt = conn.createStatement();
  118.  
  119. System.out.println(cost);
  120. System.out.println("update cdr set cdrcost ='" + cost + "' where src ='9035020090'");
  121. stmt.executeUpdate("update cdr set cdrcost ='" + cost + "' where src ='9035020090'");
  122.  
  123. // stmt.executeUpdate("insert into cdrcost (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield,cdrcost) values ('" + calldate + "','" + clid + "','" + src + "','" + dst + "','" + dcontext + "','" + channel + "','" + dstchannel + "','" + lastapp + "','" + lastdata + "','" + duration + "','" + billsec + "','" + disposition + "','" + amaflags + "','" + accountcode + "','" + uniqueid + "','" + userfield + "','" + cost + "')");
  124. } catch (Exception e) {
  125. System.out.println(e);
  126. }
  127. }
  128.  
  129. }
  130. }
Add Comment
Please, Sign In to add comment