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 ?
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); } } }
thankyou sir
what do if we have to store the result of calculation into a new table of database?
Ads