Results 1 to 7 of 7
- 06-15-2012, 07:39 AM #1
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
calculate making problem while using while() loop in ResultSet
Have A Happy Day To All!
.gif)
i wants to calculate the total value of total rows of the particular column (Total)
this is my java code
Java Code:float total=0.0f; public void getFeeTotal() { try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "root"); PreparedStatement ps100 = conn.prepareStatement("select Total from fees where AdmisonNo=? and Name=?"); ps100.setString(1, Adno.getText()); ps100.setString(2, nmm.getText()); ResultSet rs100 = ps100.executeQuery(); while (rs100.next()) { float mmm = rs100.getFloat(1); //for(int n=1;n<rs100.getRow();n++) { float temp=mmm; total=mmm+temp; } System.Out.Println(total) } conn.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
values in column of total are
i wants to calculate the total value of above (Total) field ..,Java Code:Total 25750.0 800.0 36000.0 16200.0
what changes i have to do with my code sir..,
Thank you sir..,
- 06-15-2012, 08:43 AM #2
Member
- Join Date
- Jun 2012
- Posts
- 4
- Rep Power
- 0
Re: calculate making problem while using while() loop in ResultSet
while (rs100.next())
{
float mmm = rs100.getFloat(1);
total=total+mmm;
}
System.Out.Println(total);
- 06-15-2012, 08:58 AM #3
Member
- Join Date
- Jan 2011
- Location
- Bielefeld, Germany
- Posts
- 10
- Rep Power
- 0
Re: calculate making problem while using while() loop in ResultSet
change your SQL-Statement to
and mySQL calculates the sum for you...Java Code:select sum(Total) from fees where AdmisonNo=? and Name=?
- 06-15-2012, 09:35 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: calculate making problem while using while() loop in ResultSet
There I was, reading the OP thinking "why not just use SQL?" and all ready to post, and see achill beat me to it...
:)Please do not ask for code as refusal often offends.
- 06-15-2012, 10:23 AM #5
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Re: calculate making problem while using while() loop in ResultSet
Thank you very much sir!
i try now self by your idea..,
- 06-16-2012, 06:51 AM #6
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Re: calculate making problem while using while() loop in ResultSet
sir i have no way to thanks you.
Because you each and every brainpower teach me a lesson by our technology for each time..,
Thank you! very much, it is working well sir..,
- 06-18-2012, 08:30 AM #7
Member
- Join Date
- Jan 2011
- Location
- Bielefeld, Germany
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Problem with ResultSet when using GUI
By RefugeX in forum New To JavaReplies: 6Last Post: 12-01-2011, 10:21 PM -
Using for-loop and arrays to calculate factorials and fibonacci sequence
By baumboards in forum New To JavaReplies: 8Last Post: 03-10-2011, 03:16 AM -
Making a loop and creating variables based off of user input
By seanfmglobal in forum New To JavaReplies: 2Last Post: 01-13-2011, 05:43 AM -
How to Determine prime number and making shape using loop?
By cyzash in forum New To JavaReplies: 10Last Post: 02-20-2010, 08:25 PM -
Problem with ResultSet
By flaquitqm in forum JDBCReplies: 8Last Post: 01-27-2010, 08:49 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks