retrieve data from mysql database and store it in a variable ?



Share on Google+Share on Google+

shelly arora
retrieve data from mysql database and store it in a variable ?
3 Answer(s)      4 years and 11 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 ?

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{

        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from numbers");
            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:


Advertisement null