Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners adding some value to new column
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Neo Java Developer
adding some value to new column
1 Answer(s)      4 years ago
Posted in : Java Beginners


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


Advertisement
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...; Above code is used for adding a new column in the database table and takes
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...- alter table [table name] add column [new column name] varchar (20); Thanks
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
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
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
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
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
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
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
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
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
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
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... of program: In this program, we will see how to add (append) a new column in JTable
SQL Add Column
; SQL Add Column is used to add a new column in the existing table... add a new column to the table. The Syntax for the Add Column is given... Query define a Alter Table that modifies and add a new column 'Stu_Class
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
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
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
Mysql Alter Add Column
and add a new column to it. Understand with Example...' and add a new column 'city' to the existing table 'employees... Mysql Alter Add Column     
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
Adding an employee
Adding an employee  coding for adding an employee
SQL Add Column Int
; SQL Add Column Int is used to add new column, whose field data type... to alter the table table_name.The Add keyword is used to add a new column... you a modified Stu_Table using Alter keywords, which add a new column
 

 

 

DMCA.com