aspose file tools*
The moose likes JDBC and the fly likes Aggregate functions problem in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Aggregate functions problem in jsp" Watch "Aggregate functions problem in jsp" New topic
Author

Aggregate functions problem in jsp

Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34

This is the error i got.. Please help me out..
An error occurred at line: 30 in the jsp file: /computation.jsp
Resultset cannot be resolved to a type
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You should not write Java code in a JSP file. This technique is highly discouraged and simply receipt for trouble. Write Java code in a Java class. In JSP files you should use taglibs and EL to access and present data.

Write all the JDBC code in an independent database acess class which you can easily run/test independently as Java applicaiton using main(). Create a servlet which instantiates/invokes the database class, exchange the data, puts results in the desired scope and forwards the request to the JSP. In JSP file you use taglibs (e.g. JSTL) and EL to access and present data.
Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34
can you brief me on this.. i didnt understand!
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Remove all raw Java code (scriptlets) from your JSP.
Put Java code in Java classes.
Pradeep Arun
Greenhorn

Joined: Dec 28, 2007
Posts: 19
Sujay,

Please try the below.

s.executeQuery (YOUR QUERY GOES HERE);
ResultSet rs = s.getResultSet ();
rs.getInt (VALUE THAT YOU ARE RETRIEVING);

Also check whether you included all the import statement in the jsp.

If the above didnt work, please share the complete jsp code with import statments.

Thanks,
Pradeep
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The initial problem is that he's forgotten to import the in the compilation error mentioned type or that there is a typo in it.

That does still not remove the design problem however.
Pradeep Arun
Greenhorn

Joined: Dec 28, 2007
Posts: 19
Agreed. It doesnt solve the design problem.

Sujay - You must definetly revist your design. It is not good to embed JDBC calls in jsp.

Thanks,
Pradeep
Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34


the above one is the java file


and this is the jsp file.. I dont understand the problem.
I have never done jsp with java as you are saying..Kindly help me out with the code as this is the last part left in my BE project.. I will understand when corrections are made in code!! thank you for the help..awaiting your response!!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Bauke has already given you the answer - there is a typo in your import statements. Look at the import statements; do you see what is wrong?


I will understand when corrections are made in code!! thank you for the help..awaiting your response!!

A tip: its easier and less painful when learning any technology to try to do things in a neat and ordered way and follow best practice as far as you can so you understand what is happening and why. It might feel quicker and easier but trying to work with a mess and think "I'll fix that later" but it usually just makes the whole process longer and harder.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34
Hey thanks!! i completely agree with you!! I dont see any mistakes in the import statements!! can you guide me on that!! i have never written any jsp program with java scriplets!! can you give me any link where i can learn it!!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Here is a good place to start, and here is a more specific link for the offending tag.

Compare the two import statements you have in your JSP. Is there anything different about the two?
Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34
ok now i am not gettin any error!! but how do i print the result
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18650
    
    8

What do you mean, "print" the result? This code is in a JSP, so the normal thing to do would be to send the data to the JSP's response. Are you asking how to do that?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Why do you call st.getResultSet();
What are you trying to do there?
You already have the resultset here: ResultSet rs = st.executeQuery(query);


OCUP UML fundamental and ITIL foundation
youtube channel
Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34
What I basically want to do is first find the sum of one coloumn. let that be called Total
Then I want to divide each entity of that coloumn with the total!! i dont know how to do it!!Kindly help me out
Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34
I have a table like this in Mysql
Mcap Weight
100
200
300

Total of mcap is 600 which i have it in resultset. Now i want to divide 100 by 600,200 by 600 and so on and store it in the weight coloumn!! please help me out! Please
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Would this query help you?
Attention, you will get a divide by zero error when the sum is 0.



(yourtable is two times your table)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18650
    
    8

You could do that. Although if this were a real application, you would read all the rows from an ordinary selection and put them into a List of some kind of problem-specific object. As you were doing this you could add up the mcap columns and store that total somewhere else.

Then in the view portion, you would have access to each of the problem-specific objects (including mcap for each of them) and to the total number. Divide at that point.
Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34
hey paul and jan thank you!! paul can you gimme a link or an example of how to do the things that you told?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Aggregate functions problem in jsp