adding some value to new column

adding some value to new column

how to update a column having some value into new column that also have some value i need to add this two value in java using result set we can get all the column data but how to add these value

View Answers

October 22, 2010 at 1:06 PM

Hi Friend,

Try the following code:

import java.sql.*;
public class UpdateColumn{
    public static void main(String args[])throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery("select * from leaveData");
        String bal="";
        String ide="";
        String tbal="";
        while(rs.next()){
            ide+=rs.getString(1)+" ";
            bal+=rs.getString(2)+" ";
            tbal+=rs.getString(3)+" ";
        }
        String idd[]=ide.split(" ");
        String balance[]=bal.split(" ");
        String tbalance[]=tbal.split(" ");

        for (int j=0;j<balance.length;j++)
        {
            int id=Integer.parseInt(idd[j]);
            int b=Integer.parseInt(balance[j]);
            int total=Integer.parseInt(tbalance[j]);
            int totalBalance=b+total;
            st.executeUpdate("update leaveData set leaveTotal="+totalBalance+" where leaveid="+id+"");
        }
    }
}

For the above code, we have created a table 'leaveData'

CREATE TABLE leavedata (
leaveid bigint(20) NOT NULL auto_increment,
leaveBalance int(11) default NULL,
leaveTotal int(11) default NULL,
PRIMARY KEY (leaveid)
)

Thanks









Related Tutorials/Questions & Answers:
adding some value to new column
adding some value to new column   how to update a column having some value into new column that also have some value i need to add this two value in java using result set we can get all the column data but how to add these value
Adding a New Column Name in Database Table
Adding a New Column Name in Database Table  ... are going to learn about adding a new column in database table. Sometimes it happens...; data_type; Above code is used for adding a new column in the database table
Advertisements
javascript adding a value to an array
javascript adding a value to an array  How to add a value to a function argument or an array in JavaScript
How to Delete a column and Add a new column to database
How to Delete a column and Add a new column to database   How to Delete a column and Add a new column to database   Hi, The following... a column in a table- alter table [table name] add column [new column name] varchar
Adding a flex table in another flex table column
Adding a flex table in another flex table column  how to add a flex table in another flex table column
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER TABLE table_name ADD column_name column-definition Suppose, we have a table
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER TABLE table_name ADD column_name column-definition Suppose, we have a table
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER TABLE table_name ADD column_name column-definition Suppose, we have a table
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER TABLE table_name ADD column_name column-definition Suppose, we have a table
SQL add column default value
SQL add column default value       Add a Column default value is used in SQL, When create... to the column ,when no value is inserted to the column . Understand
while Append need a new line for column and row
while Append need a new line for column and row  HI While using append in javascript for retreiving the rows and its column header, its retreiving but after column header i need new line but it is not coming. Thanks in advance
Mysql Add Column Default Value
Mysql Add Column Default Value       Mysql Add Column Default Value is used to add the default value to the column. The records take a default value when there is no value
SQL add column default value
SQL add column default value       Add a Column default value is used in SQL, When... is given to the column ,when no value is inserted to the column
Find Value of Column
Find Value of Column       In this program we are going to find the value of row from the column of  an excel sheet using POI3.0 API Event
SQL Alter Column Default Value
SQL Alter Column Default Value       Alter Column Default Value in  SQL Server is used... column. The use of default value is specified when insert is performed
insert/update records with some of the columns having NULL value.
insert/update records with some of the columns having NULL value.  How do I insert/update records with some of the columns having NULL value
Adding text in to text area of jframe at new line with different background colour
Adding text in to text area of jframe at new line with different background colour  Hi, I am reading text from text file and i want to write... to write that text every time at new line in text area with different background
Finding MAX value from emp_id column using SQL query?
Finding MAX value from emp_id column using SQL query?  I need... the command which selects max value till 10 but after that it fails to pick max value of emp id from the table.(Actually it picks up Max value using by looking at 1st
Column count doesn't match value count at row 1
Column count doesn't match value count at row 1  Column count doesn't match value count at row 1 UPDATE user_profile SET id=[value-1],user_id=[value-2],full_name=[value-3],mobile_phone=[value-4],hide_email_id=[value-5],hide
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.  Write a java program that encrypt and decrypt some string by adding or removing 2 on each character. Example 1 : Please Enter
SQL Alter Column Default Value
SQL Alter Column Default Value       Alter Column Default Value in  SQL Server... specified column. The use of default value is specified when insert
Add new column to table using DBCP
Appending a Column in JTable
;  In this section, you will see how to add a new column in JTable. For adding a new column in JTable component you have to need a table model... column in JTable. The following program creates a table that contains some data
SQL Add Column
; SQL Add Column is used to add a new column in the existing table... Column Syntax The Alter Table modifies and ADD Keywords add a new... Query define a Alter Table that modifies and add a new column 'Stu_Class
how to display each arraylist value on new page in jsp
how to display each arraylist value on new page in jsp  hi!!!! i want to display each arraylist value on new page in jsp????? and also want to access the arraylist values using next button..... any help would be appreciated
hi,i'am new to Jsp.Can some one please let me know an answer for this question?
hi,i'am new to Jsp.Can some one please let me know an answer for this question?  how do we upload an xml file and validate them against WIPO DTD
Mysql Alter Add Column
and add a new column to it. Understand with ExampleADS...) Query to alter Table named employees by adding column named city...' and add a new column 'city' to the existing table 'employees
my table should be reseted to new value upon the selection of the combo box..
my table should be reseted to new value upon the selection of the combo box... new form purchase */ public purchase() { try { Class.forName... Container cp = getContentPane(); cp.setLayout(new FlowLayout()); model = new
java.sql.SQLException: Column count doesn't match value count at row 1 - JSP-Servlet
java.sql.SQLException: Column count doesn't match value count at row 1 ... of : java.sql.SQLException: Column count doesn't match value count at row 1 I checked the No. of column in table and values in row are same. I don't know whats
SQL Add Column Int
; SQL Add Column Int is used to add new column, whose field data type..._name.The Add keyword is used to add a new column in a table... using Alter keywords, which add a new column Stu_Class using add keyword
MySQL Append Column
MySQL Append Column This example illustrates how to append two column value of a table. In this example create a select query to append the data of four column. Table
new
new   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType...="radio" name="sex" value="male">Male <input type="radio" name="sex" value="female">Female<br><br>
how insert data from databse in array and compare new data to already stored value in array
to stored it in an array and i want to compare new value that come from database with array if this new value is already stored in this array i like to executed...how insert data from databse in array and compare new data to already stored
how to Change column name and Make a unique column.
a column- alter table [table name] change [old column name] [new column name...how to Change column name and Make a unique column.   how to Change column name and Make a unique column.   Hi, Following queries
new
new    hi i am jane pls explain the difference between string greeting = good morning string greeting = new string ("good morning
new
new    hi i am jane pls explain the difference between heap memory and stack memory
new
new  hi the difference between string sname = good morning string sname =new("good morning
updating column automatically based on system date
(that also have common value like 25) i need to update this new column based on system...,leave balance,etc are column),in leave balance column each employee has some leave...updating column automatically based on system date  hi, can any one
MySQL Add Column
a new column 'address' to the existing table 'employee'.ADS_TO_REPLACE_2 ALTER... MySQL Add Column       MySQL Add Column is used to add the column to the existing table. The Alter table
MySQL Add Column
employee is used to modify the table 'employee' and add a new column 'address... MySQL Add Column       MySQL Add Column is used to add the column to the existing table
Auto generated column in sql 5.0 - SQL
Auto generated column in sql 5.0  hi, in my data base i have declared one column has auto generating but currently am not able to insert the data unless i need to pass some integer value to that column.. regards pramod.k.r
Change Column Name in MySQL
to change the column name to new_col it can be done using the syntax given below..._col: The old column name that you want to change. new_col: The new column name data_type: This is a data type of new column. First of all you will create
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
Adding an employee
Adding an employee  coding for adding an employee
adding loop
adding loop  Hi I have a program that is not compiling when I add... []args){ ArrayList<HardwareItems> list=new ArrayList<HardwareItems>(); list.add(new HardwareItems("K16","Wood screws,brass,20mm",7.75
adding a dialogue
adding a dialogue  Blockquote Hi can you help with the program...=new Scanner(System.in); System.out.println("Enter Code (XX to stop... void main(String[] args) { Scanner input=new Scanner(System.in
Column select
Column select   How i fetch Experience wise resume?   Create a column experience which consist of only two values either yes...;td>Name</td><td><input type="text" name="name" value="<
New PHP 7.4 Release: The Features and Value Additions
PHP 7.4 new features - New PHP 7.4 Release: The Features and Value Additions... this year. Let us have a brief look at all the new features and value additions of new PHP 7.4. What PHP 7.4 Will Bring? ADS_TO_REPLACE_1 Compared
Blob column
Blob column  Hi all... How to store an excel file in Blob column? I m using oracle 11 g database

Ads