Home Answers Viewqa JDBC Data is not inserting correctly in mysql database.

 
 


vikas pandey
Data is not inserting correctly in mysql database.
0 Answer(s)      8 months ago
Posted in : JDBC

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









Related Pages:
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
Inserting Data into mysql - SQL
(using php)and inserting the details in a mysql database. Lets take for instance, a csv file named books and a database table named books as well both...Inserting Data into mysql  My sincere apologize for this post. I
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
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
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following... to a databse by a servlet.I used the example in "Inserting Data In Database table... of a table,that is none of the data which i tried to enter into database by using
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
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has...' is MySQl command. So change it into database.Set the field 'options' instead
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, i am getting error in my code of feedback form. once i finished selecting all the radio buttons... an error in your SQL syntax; check the manual that corresponds to your MySQL
inserting image in mysql database using browse button in servlets
inserting image in mysql database using browse button in servlets  Hi,I want to insert a image in mysql database using browse button. and, i want... ENCTYPE="multipart/form-data" ACTION="../UploadServlet" METHOD=POST> <br>
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
Inserting values in MySQL database table
Inserting values in MySQL database table   ... insert values in the MySQL database table. We know that tables store data in rows... the facility for inserting the values in MySQL database table. Description
inserting value - JSP-Servlet
the database mySQl with the help of servlet. Inserting form data   Inserting form data into database using JSP and ServletGiven code will illustrate you, how one can get data into database using JSP and ServletExample Code
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 in Database Table
Inserting Image in Database Table   ... to the MySQL database table.  Flow of the process : This program helps the user to insert an image in the MySQL database table. To insert
iBatis-Inserting data into database
iBatis-Inserting data into database   ... is inserting a row into database. And for this we are using MySQL as a database... namespace="Contact"> <!--- Inserting data in table --> <
Problem in inserting clob data in jsp
Problem in inserting clob data in jsp  how to insert any rich text editor data (which have more than 32766 characters) in a clob type column of oracle database with jsp
pbml in inserting selected item from combobox into mysql - XML
successfully.alert box have to display only if data was stored in database otherwise it has...pbml in inserting selected item from combobox into mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide
hibernate firstExample not inserting data - Hibernate
problem is data is not inserting into DB even though the program is executed... DEFAULT CHARSET=latin1 data is not inserting...hibernate firstExample not inserting data  hello all , i followed
Inserting a value to an Enum field in Table
as a 'N' but I get some database error that says data truncated. How do I set...Inserting a value to an Enum field in Table  I'm writing a code that creates a user account and sends the result to the user table in a mysql
Inserting Data In Database table using Statement
Inserting Data In Database table using Statement... to insert the data in the database from our java program in the table stored... of the PrintWriter class. We can insert the data in the database only and only
Insert Data in Table Using Stored Procedure
Insert Data in Table Using Stored Procedure        In this example we are inserting data into a table using stored procedure. Steps: 1.Create database: To create
Inserting data in Excel File - Java Beginners
Inserting data in Excel File  Dear Sir, How can we fill the excel with fetched data from the database like Oracle, DB2? Is it possible to create an excel with filled data? Kindly give me the solutions to questions
Inserting Mysql CLOB data using Servlet
Inserting Mysql CLOB data using Servlet In this Section, we will insert "... in a Database table. CLOB data is used to store a block of text. It is designed... statement. Creating CLOB data type in Mysql table In Mysql, CLOB data type is of 4
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, my problem is as follows: i am creating a feedback form of a college. this feedback form... button) now i have a database as professor and a table in this database
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
MySQL Database Training
MySQL data with SQL. How to create a simple MySQL database Table... MySQL Database Training        MySQL Training Course Objectives How
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>
Lock while inserting/updating database in multithreaded.
Lock while inserting/updating database in multithreaded.  Hi, I am having a multithreaded process which replicates the data from many table to one... inserting/updating to database. I dont know what is the issue but it was never
Inserting data from the HTML page to the database
Inserting data from the HTML page to the database... of the PrintWriter class. We can insert the data in the database only and only... program in which we are going to insert the values in the database table from
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
Mapping MySQL Data Types in Java
Mapping MySQL Data Types in Java       Data types of MySQL and Java programming language are not same, its need some mechanism for transferring data between an database
MySQL Database
MySQL Database       MYSQL...; The Database Design for MySQL Database Designer for MySQL is a handy tool... for MySQL database and takes into account its features.  Our Database Designer
Inserting Image in a database Table
Inserting Image in MySql Database Table... understand the concept of inserting a image in the database table, so go through... program we need to make a connection between our java class and the MySql
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
MySQL Creating and Deleting Database
MySQL Creating and Deleting Database   ... and delete the database in MySQL. MySQL provides the both commands. In this section you...'); After inserting the data into the table, now we discuss about retrieving the data
Insert data in database by using sql tag of JSTL SQL library
are going to create application that update database by inserting data given by user. To update database first create a data source and then execute insert sql... Insert data in database by using sql tag of JSTL SQL library
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
Correctly Open and Close database connection
; } Completely Open and Close A Database Connection Database Connection... depends on database connectivity. Therefore it is very important to open and close database connections properly. If any database connection is open
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
Inserting a row using PreparedStatement
;    String url = "jdbc:mysql://192.168.10.13
FORM Tag Correctly for Uploading Files.
FORM Tag Correctly for Uploading Files.  How To Write the FORM Tag Correctly for Uploading Files?   Hi friends, When you clicks the submit... METHOD as "post" and ENCTYPE as "multipart/form-data" in order for the uploading
Inserting Image(s) - JSP-Servlet
Inserting Image(s)  Hello, I need sample code using java servlet and html form and explanation on how to insert and retrieve image from mysql. ... = null; String url = "jdbc:mysql://localhost:3306/"; String db = "
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 Restore The Lossed data in MYSQL database after the System is formatted
How to Restore The Lossed data in MYSQL database after the System is formatted  How to Restore The Lossed data in MYSQL database after the System is formatted
problem in inserting data in databases created in netbeans using jsp..
problem in inserting data in databases created in netbeans using jsp.. ... = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root...+")"); out.println("Data is successfully inserted!"); } catch(Exception e
MySql database - SQL
to retrieve the data from Ms-access then you create a database , table and create a connection with this. Then you retrieve the data from the database. Thanks...MySql database  hello sir, i am trying to write a code which should
Inserting Image into table
Inserting Image into table  In this section , we will insert a image into a table. For inserting image, table's field (in which image...)) For inserting whole image, we have to create an 'InputStream'
JDBC Example with MySQL
for transferring data between an database using MySQL data types and a application using Java data types. Connecting to a MySQL Database in Java In this section... a database that is a collection of data or information. Inserting values
Insert  Image into Database Using Servlet
of inserting image into database table using Servlet. This type of program is useful... the image data into database. PreparedStatement ps = ... Insert  Image into Database Using Servlet   
Insert Image into Database Using Servlet
: The following code is actually used to save the image data into database...Insert  Image into Database Using Servlet       This example illustrate the process of inserting