Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Data is not inserting into mysql database [closed]
- private static String destination;
- public static void main(String[] args) {
- ArrayList data = new ArrayList();
- String str = "9035";
- int cost = 0;
- String AreaCode = null;
- int Rate = 0;
- int dur = 0;
- String calldate = null;
- String clid = null;
- String src = null;
- String dst = null;
- String dcontext = null;
- String channel = null;
- String dstchannel = null;
- String lastapp = null;
- String duration = null;
- String lastdata = null;
- String billsec = null;
- String disposition = null;
- String amaflags = null;
- String accountcode = null;
- String uniqueid = null;
- String userfield = null;
- try {
- Connection con = null;
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/asteriskcdrdb", "root", "techsoft");
- Statement st = con.createStatement();
- ResultSet rs = st.executeQuery("Select * from asteriskcdrdb.sp1 where areacode = '" + str + "'");
- while (rs.next()) {
- AreaCode = rs.getString("AreaCode");
- //System.out.println(AreaCode);
- String Pulse = rs.getString("Pulse");
- Rate = rs.getInt("Rate/pulse");
- // System.out.println(Rate);
- }
- rs.close();
- st.close();
- } catch (Exception e) {
- System.out.println(e);
- }
- if (AreaCode.equals(str)) {
- //System.out.println("Hii");
- try {
- Connection conn = null;
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/asteriskcdrdb", "root", "techsoft");
- Statement stmt = conn.createStatement();
- ResultSet rst = stmt.executeQuery("Select * from cdr where src ='9035020090'");
- while (rst.next()) {
- while (rst.next()) {
- calldate = rst.getString("calldate");
- //System.out.println(calldate);
- clid = rst.getString("clid");
- src = rst.getString("src");
- dst = rst.getString("dst");
- dcontext = rst.getString("dcontext");
- channel = rst.getString("channel");
- dstchannel = rst.getString("dstchannel");
- lastapp = rst.getString("lastapp");
- lastdata = rst.getString("lastdata");
- duration = rst.getString("duration");
- // System.out.println(duration);
- dur = Integer.parseInt(duration);
- data.add(dur);
- //System.out.println(dur);
- billsec = rst.getString("billsec");
- disposition = rst.getString("disposition");
- amaflags = rst.getString("amaflags");
- accountcode = rst.getString("accountcode");
- uniqueid = rst.getString("uniqueid");
- userfield = rst.getString("userfield");
- }
- }
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- for (int i = 0; i < data.size(); i++) {
- System.out.println(data);
- int c=(int) data.get(i);
- System.out.println(c);
- int min = 60;
- // System.out.println(dur);
- int quotient = c / min;
- // System.out.println(quotient);
- int reminder =c % min;
- // System.out.println(reminder);
- if (reminder > 0) {
- quotient = quotient + 1;
- System.out.println(quotient);
- cost = quotient * Rate;
- System.out.println(cost);
- try {
- Connection conn = null;
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/asteriskcdrdb", "root",
- "techsoft");
- Statement stmt = conn.createStatement();
- System.out.println(cost);
- System.out.println("update cdr set cdrcost ='" + cost + "' where src ='9035020090'");
- stmt.executeUpdate("update cdr set cdrcost ='" + cost + "' where src ='9035020090'");
- // 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 + "')");
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment