store data from a variable in mysql?

store data from a variable in mysql?

sir last time asked you tell me how to retrieve data from a database mysql and store it in an int variable in order to apply some calculation on it, but now i want to store the result of the calculation from an int variable into mysql in a new table of database. how to do this..?

View Answers

June 25, 2012 at 5:02 PM

Here is an example that retrieve the integer values from the database and stored in the integer variables. In addition to it, we have added numbers that are retrieved from the database. The sum of numbers is then saved to another table.

import java.sql.*;

class RetrieveData 
    public static void main(String[] args) throws Exception{

        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from numbers");
        Statement stmt=conn.createStatement();
            int num1=rs.getInt("number1");
            int num2=rs.getInt("number2");
            int sum=num1+num2;

            System.out.println(num1+" +\t "+num2+" =\t "+sum);
                        int i=stmt.executeUpdate("insert into result(result) values("+sum+")");



Related Tutorials/Questions & Answers:
store data from a variable in mysql?
retrieve data from mysql database and store it in a variable ?
Getting Json data from servlet to javascript variable
select maximum from table and hoe to store it in any variable
Store data in HTML forms from Excel sheet
Store Variable in Java
how to store JTree data hierarchically in mysql database from netbeans
I want to store the value of local variable into Global variable
Extracting variable from jsp
declare a variable that will store an array of 5 objects
Store ResultSt Data in a Map
iPad App to store data
Getting environment variable value from java
store and retrive image from the database
store and retrieve data
servlet program for data store in oracle?
Java Xml Data Store
store form data into word document
how to store,retrieve,modify the data
data type used to store name.(getting an error)
ModuleNotFoundError: No module named 'mysqlx-connector'
read from file and store using hash map
store value in checkbox from gridview
unable to get value returned from javascript variable in page
store & retrive the image from oracle database
project in JSP and XML(to store data)
to store data entered in html page
Getting data from servlet into javascript
Assign value from a <bean:write> tag to a variable
How to store and retrieve image from database in JSP?
ModuleNotFoundError: No module named 'nifeng-data-store'