Data is not inserting correctly in mysql database.

Ads
 

Data is not inserting correctly in mysql database.

Hello Sir, below is my code to insert data into database by list iteration through for loop but it is not getting inserted ..it is taking only one value for each data cloumn ..at the time of end of the query... PLz see my code and point my mistake. Thank you Sir...

import java.io.*; import java.math.BigDecimal; import java.sql.*; import java.util.*;

public class NewProcessing {

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);
            }
        }

    }
}

}

View Answers

Ads









Related Tutorials/Questions & Answers:
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration... for each data cloumn ..at the time of end of the query... PLz see my code and point my
problem on jsp, inserting data into table(mysql).
problem on jsp, inserting data into table(mysql).  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table name also is given by the user.My database
Advertisements
inserting into mysql database with uid to be primary key and autoincrement
inserting into mysql database with uid to be primary key and autoincrement  hello, i am new to jsp and facing problem in creating a database entry...; Here is the code of inserting values from jsp form to database
php inserting date into mysql
php inserting date into mysql  php inserting date into mysql   Here is a php code that inserts date into mysql database. In the given code, data is a database table. <?php table $query_manual = "INSERT INTO data
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql database using php.... below my code is that.. <html> <head>
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... from the dropdown, related data will get displayed on the textboxes. Here we have
update data to mysql database through JTextField
update data to mysql database through JTextField  I am getting an error, when i am updating a data to mysql database through JTextField. Send me...(); JOptionPane.showMessageDialog(null,"Data successfully Updated to the database
inserting multiple file formats into database
inserting multiple file formats into database  hi i want to insert multiple file format like .pdf.doc.zip into mysql database using jsp
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
inserting data into datafields
inserting data into datafields  I was raised with a query.... there is a button, on click on it....... few fields regenerates and the details entered there should be inserted into Database Number of times we click that button
retrieve data from mysql database and store it in a variable ?
retrieve data from mysql database and store it in a variable ?  sir , I am working on a project , in which I have to apply operation on input data which is stored in mysql. so to apply some arithmetic operation on it we have
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  how to send data from mysql database to google chart api using java
Inserting id in place of name to database
Inserting id in place of name to database  Hello, I have a database department where I have "id" and "name". I am fetching this data to a jsp form in dropdown list displaying "name" there and Now I wanted to insert data from
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
how to store JTree data hierarchically in mysql database from netbeans
how to store JTree data hierarchically in mysql database from netbeans  how to store JTree data hierarchically in mysql database from netbeans. I am new to this topics so I need a program and tables you are using in database
Export data in excel sheet via Browse and upload button into mysql database
Export data in excel sheet via Browse and upload button into mysql database  how to create a Browse & Upload Buttons and then save the information from it in mysql database's Table Am using struts2,hibernate for making
retrieve related data from database using jsp and mysql
retrieve related data from database using jsp and mysql  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list. if we change a value in a dropdown its related value must
Data needs to be gathered in XML file from the database (MySql) using JSP
Data needs to be gathered in XML file from the database (MySql) using JSP ... data regarding particular id from the database table. Data needs to be gathered in XML file from the database (MySql) using appropriate JSP/Java Bean functions
dynamic retrivel of data from mysql database in table format at jsp
dynamic retrivel of data from mysql database in table format at jsp  ... the data from database and display it as table format in jsp... For example, i have created database with fields lik groups,membername ,amount and so on.... let
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
how to fetch data from mysql database table and draw a bar chart on that data using in jsp  how to create bar chart fetch data from mysql database using in jsp.please give me a right code. yhanks in advance
JDBC Video tutorial - How to update Data in a MySQL Database?
JDBC Beginners tutorial for updating the data into MySQL database The Java... in Java for updating the data in a MySQL database table. We have used the update... the example program for updating the data into MySQL database using the JDBC driver
how to retrive the particular data from database in php with mysql?
how to retrive the particular data from database in php with mysql?  ..._db("samp", $con); $Name=$_POST['unames']; $data=mysql_query("SELECT * FROM tbl_sample where Name='$Name'"); /*$info=mysql_fetch_array($data);*/ while
JDBC Video tutorial - How to read Data from MySQL Database?
JDBC Beginners tutorial for reading the data from MySQL database.... Steps for reading the data from MySQL database in a Java program: Step 1: Connect... following are the steps to delete data in database: Connect to MySQL Database
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  Добовляйтесь в группу "МАЙНКРАФТА" Будьте участниками Группы Помогаите нам и себе Наша группа https://vk.com/club60851464 Есть свой сервер! Хорошая атмосфера
JDBC Video tutorial - How to delete Data in a MySQL Database?
JDBC Beginners tutorial for deleting the data into MySQL database... in Java for deleting the data in a MySQL database table. We have used... the data from Java program: Step 1: Connect to the MySQL database Following code
dynamic retrival of data from mysql database to dropdownlist in jsp
dynamic retrival of data from mysql database to dropdownlist in jsp  Hello, Am having problem in my project... i want to retrive the data from mysql... name from the mysql database to the dropdownlist.if the user select the particular
MYSQL Database
MYSQL Database  Can any one brief me about how to use MYSQL Database to store the create new database, create tables. Thanks.   Hi, the MySQL database server is most popular database server and if you want to know
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  http://www.roseindia.net/answers/viewqa/Ajax/15250-DropDown-in-ajax+jsp.html... to insert all selected values in data base correspondent to each like if user
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... and then the result at the end.I need to add simple database connectivity... help me out quickly i am searching a lot..creating teh database si ok
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... and then the result at the end.I need to add simple database connectivity... help me out quickly i am searching a lot..creating teh database si ok
inserting multiple file formats into database using html
inserting multiple file formats into database using html   hi the code was working fine,i want to choose the file and then upload to database,by using html.whether it is possible to upload larger file size,please explain

Ads