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
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
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
Advertisements
Inserting data on a database in servlet - JSP-ServletInserting 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
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 php inserting date into mysqlphp
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 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
retrieve data from mysql databaseretrieve
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>
Insert Data in Table Using Stored Procedure data into a table
using stored procedure.
Steps:
1.Create
database...
mysql > create
database Employee;
Query OK... is the video tutorial of Creating and calling the Stored Procedure in
MySQL Database Data retrieve from mysql databaseData 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
inserting data into datafieldsinserting 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
update data to mysql database through JTextFieldupdate
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 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...;
<!---
Inserting data in table -->
<insert id="insert
Problem in inserting clob data in jspProblem 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
Inserting id in place of name to databaseInserting 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 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
retrieve related data from database using jsp and mysqlretrieve 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
Inserting data in Excel File - Java BeginnersInserting 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
MySQL Database Training MySQL data with SQL.
How to create a simple
MySQL
database Table...
MySQL Database Training
MySQL
Training Course Objectives
How
Inserting Image in Database Table Inserting Image in
Database Table
...
to the
MySQL database table.
Flow of the process :
ADS_TO_REPLACE_1
This program helps the user to
insert
an image in the
MySQL database table
inserting an path of an image in database - JDBCinserting an path of an image in database hello
kindly help related... time its full path should be inserted in the
database(MS Sql 2000)..
I m able... be saved in the
database...I have tried it but getting an error..
plz have a look
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
MYSQL DatabaseMYSQL 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