A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Databases
»
JDBC
Author
Problem in Divison
Sujay Nadkarni
Ranch Hand
Joined: Jul 03, 2008
Posts: 34
posted
Mar 31, 2009 07:03:12
0
<%@ page import="java.sql.*" %> <%@page import="java.util.*"%> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Computation</title> </head> <body> <% String n=request.getParameter("Index_name"); String m="Update"; String o="SET mcap=dayc*shares"; String g="Select SUM(mcap) AS t from"; String l="SET wt="; %> <% Connection connection = DriverManager.getConnection( "jdbc:odbc:BE"); Statement statement=connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); String string=m+' '+n+' '+o; int i=statement.executeUpdate(string); String query=g+' '+n; Connection conn = DriverManager.getConnection( "jdbc:odbc:BE"); Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String sti="Select mcap from Nifty"; ResultSet rs = st.executeQuery(query); while(rs.next()){ float x=rs.getFloat("t"); } ResultSet rsi=st.executeQuery(sti); while(rsi.next()){ float p=rsi.getFloat("mcap"); } %> </body> </html>
I found out the values and stored it in x and p.
Since x is the result of aggregate function it contains only one value. P contains multiple value.
Now I want to divide each value stored in p with x and insert it into the database. How do i do that?
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
I like...
posted
Mar 31, 2009 08:13:38
0
P contains multiple value.
No it doesn't, unless there is only one row returned by the SQL "Select mcap from Nifty". Otherwise it contains one value which you overwrite.
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
I like...
posted
Mar 31, 2009 09:17:51
0
DO NOT USE
JDBC
INSIDE OF
JSP
!
My Blog:
Down Home Country Coding with Scott Selikoff
I agree. Here's the link:
http://jrebel.com/download
subject: Problem in Divison
Similar Threads
Aggregate functions problem in jsp
pass the value to next form
while loop in a while loop
Displaying image from dbase
database coloumn updation problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter