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



Home Answers Viewqa Java-Beginners retrieve data from mysql database and store it in a variable ?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shelly arora
retrieve data from mysql database and store it in a variable ?
3 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


sir , I am working on a project , in which I have to apply operation on input data which is stored in mysql. so to apply some arithmetic operation on it we have to store that data in int variable. how to do this ?


Advertisement
View Answers

June 22, 2012 at 3:14 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.

import java.sql.*;

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

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

            System.out.println(num1+" +\t "+num2+" =\t "+sum);

        }
    }
}


June 23, 2012 at 1:20 AM


thankyou sir



June 23, 2012 at 3:57 AM


what do if we have to store the result of calculation into a new table of database?



Related Tutorials/Questions & Answers:
 

 

 

DMCA.com