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

 
 


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

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 Pages:
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
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
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 checkbox to List as item
Adding checkbox to List as item   can we add checkox to List  ... main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list = new JList(new
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
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
new
new   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType="text...="radio" name="sex" value="male">Male <input type="radio" name="sex" value="female">Female<br><br> <
Mysql Alter Add Column
a new column to it. Understand with Example The Tutorial... by adding column named city: The Query Alter is used to define the table 'employees' and add a new column 'city' to the existing table 'employees
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
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
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
Java: Some problems in given condition
Java: Some problems in given condition   SIR, I want to get the values from the table( database), if any one of the column of the table value is 0. Then one alert should b printed in application using Java. If(att.getdata1()==0
Java Applet - Adding a Button to Decrease a Total
Java Applet - Adding a Button to Decrease a Total  Hello everyone... { public int testone = 0; public void init() { Button one = new Button... that value, and another that when clicked, will decrease the value. Thanks so much
How to refresh a jTable On adding or deleting record ....
How to refresh a jTable On adding or deleting record ....   Hii... of records.... and new record should be showed in the jtable in the panel.. Plz sir give... that updates the jtable automatically after some interval of time. import
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
How to add a column in a table
the query in the prepareStatement() for adding new column in the database... have to add a new column to our database by using the java program. There is no need to get panic. What we simply need is to use a query for adding a new
how update JTable after adding a row into database
how update JTable after adding a row into database  J have two... in JTable, and it's OK, but after adding a row into database table does't update. How update JTable after adding a row into database? package djilepak.javaclss.for
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
How to create dynamic buttons for adding products on a cart.
How to create dynamic buttons for adding products on a cart.  Hi. I have some problems creating a page to add items into a cart. The page loads... value="LOGO"/> <h:inputText id="searchTxt" size
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
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
SQL Alter Column Syntax
| DROP DEFAULT} | CHANGE [COLUMN] old_col_name new_col_name column_definition... SQL Alter Column Syntax       SQL Alter Column Syntax modifies the existing table definition
JSF column Tag
and fix these with some specific values. You can specify the value...;/body> </html> JSF column tag has some...JSF column Tag     
MySQL Add Column
the table 'employee' and add a new column 'address' to the existing table 'employee... MySQL Add Column       MySQL Add Column tutorial explains you to add the column to the existing
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
Deleting row and column from a table
minimum value and we will also delete column "name". import...;id" value and column "name"...Deleting row and column from a table  In this program ,we delete row
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
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
Setting the Column Header in JTable
how to set the column headers in JTable using JTableHeader. Java provides some... some data in row and column format by using the JTable constructor. This table... Setting the Column Header in JTable   
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
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
Dynamically adding textbox and labels
Dynamically adding textbox and labels  Sir, In my application I want to insert texbox and labels dynamically and want to insert database field value in that generated label. Plz help me, Thanks in advance
testcase for adding - JUNIT
testcase for adding  hi deepak...I am new to junit.can u send me a JUnit test case for adding or multiplying of two numbers.please i need it urgently
Inserting a Column in JTable
. After adding a column, the JTable will contain 4 columns. The new column of ... in JTable with the help of addColunm() method, after that the new column can....   targetCol_index: This is the index of new column in which
webservices adding in eclipse
webservices adding in eclipse  hi team, i am working on webservices, please guide me how to add webservices in eclispe with step by step and give some examples also.   Please visit the following link: http
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="<
Adding images in itext pdf
Adding images in itext pdf  Hi, How to add image in pdf file using itext? Thanks   Hi, You can use following code: PdfWriter.getInstance(document,new FileOutputStream("imagesPDF.pdf")); Read more at Inserting
Make Unique Column in Database Table
is executed with the help of some java methods. If column name becomes unique... Make Unique Column in Database Table   ... a unique key in a column of a database table. While declaring unique key
jtable-adding a row dynamically
jtable-adding a row dynamically  hi..i am doing a project... to add one more row dynamically as a new row 4th if the details are large.but every... row a new row 4th row shuld be formed any one can help me
Adding JTable into existing Jframe.
(100,60,1300,600); add(pane); //Action Listener for button //for adding new...Adding JTable into existing Jframe.  i need to add JTable...("serial") public class AddPage extends JFrame { JDesktopPane pane = new
Adding JTable into existing Jframe.
(100,60,1300,600); add(pane); //Action Listener for button //for adding new...Adding JTable into existing Jframe.  i need to add JTable...("serial") public class AddPage extends JFrame { JDesktopPane pane = new

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.