File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Aggregate functions problem in jsp

 
Sujay Nadkarni
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you brief me on this.. i didnt understand!
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove all raw Java code (scriptlets) from your JSP.
Put Java code in Java classes.
 
Pradeep Arun
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Sujay Nadkarni
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok now i am not gettin any error!! but how do i print the result
 
Paul Clapham
Sheriff
Pie
Posts: 20158
23
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2574
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you call st.getResultSet();
What are you trying to do there?
You already have the resultset here: ResultSet rs = st.executeQuery(query);
 
Sujay Nadkarni
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2574
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20158
23
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey paul and jan thank you!! paul can you gimme a link or an example of how to do the things that you told?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic