adding some value to new column

Ads

 
 
 

Share on Google+Share on Google+

Neo Java Developer
adding some value to new column
1 Answer(s)      6 years and 7 months 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

Ads
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


Ads









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
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
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
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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile?

Ads

 
Advertisement null

Ads