Priya Prasad

Ranch Hand
+ Follow
since Jun 11, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Priya Prasad

And it shows this error now

java.sql.SQLException: Before start of result set

I am tired.
Which means in the code i need to write

String s34 = jTextField5.getText();
if(s34=='')
s34="null";

??

or it automatically stores null?
Yes I figured out my INSERT statement was wrong and now I have replaced it with-



But my table is not taking null values. I have used Netbeans to create the table and i have check the box which says Nulls Allowed. If the user is not entering any value in the text field I want no value to get inserted in the table. How do I do that?

Ulf Dittmer wrote:That's not the right syntax for an INSERT statement. If you run that in your SQL tool you should get the same error.

By the way, have you noticed that the you're not using the CODE tags correctly? The way you're applying them they don't accomplish anything - the opening/closing tags go before/after the code. I had corrected those before, but since this is now the third time you're using them like this, please take a moment to check out how your last post looks like. You can edit it to correct the code tags.



there you go!

insert into attributetable values Color='Red',DesignName='Shiva',ReferenceCode='ncd01',S=12,M=12,L=12,XL=12, XXL='' ,FreeSize='',Undefined='',S32='',S34='',S36='',S38='', S40='',S42='',S44='',CostPrice=212.22,InValue=12.22,MRP=212.22,CodeValue='006';

gives me this error

Error code 1064, SQL state 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Color='Red',DesignName='Shiva',ReferenceCode='ncd01',S=12,M=12,L=12,XL=12, XXL='' at line 1

Color, DesignName and Reference code =varchar(100)
rest all integer
CostPrice, in value, mrp and outvalue= real
CodeValue is again varchar
Yes I am sure about that. See this.

select Code from combinationtable where Gender='Male' AND Category='T-Shirt' AND SubCategory='V-Neck' AND StyleType='Stripes';

This is what i run in SQL editor.
and the same things I run while in the Java query.

Yes you are right. I used this..



and it shows Nothing in the resultset.

WHich means I am unable to retrieve the code from the table. Now how do i do it?
On the other hand if i run the same query directly in the SQL editor it works fine.
Yes. The same statement works perfectly well and gives me the code when I use it directly against the DB. I need to use this value of Code for further processing. But somehow its not working. I need to see the value of the code in the System.out.println. But the resultset is not retrieving the data. How do I go about it?
Somehow


is not working. Any idea why?
I am trying to create a web application where I want to execute the following queries in the table called bkpl:-

1. select sum(Amount) from bkpl;
2.select sum(Amount) from bkpl where Af_Scheme_type='In-Principle' and GrantedBy='PLHO';
3..select sum(Amount) from bkpl where Af_Scheme_type='Final' and GrantedBy='PLHO';
4..select sum(Amount) from bkpl where Af_Scheme_type='In-Principle' and GrantedBy='Region';
5..select sum(Amount) from bkpl where Af_Scheme_type='Final' and GrantedBy='Region';

Now I figured out that I can use PreparedStatement but I have no idea how to fit in so many combinations with it. My piece of codes are here

in the Servlet where I could succesfully execute one query:-


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
*
* @author Priya
*/
public class MD extends HttpServlet {

Connection conn;
Statement stmt;
ResultSet res;
DatabaseConnection dbconn;
String query1, query2, query3, query4, query5, query6, query7, query8, Unit_Name;
private double Amount;
List lst = new ArrayList();

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Unit_Name = request.getParameter("Unit_Name");
dbconn = new DatabaseConnection();
conn = dbconn.setConnection();

if (Unit_Name.equals("BKPL")) {
stmt = conn.createStatement();
query1 = "Select Sum(Amount) from bkpl;";
res = dbconn.getResult(query1, conn);
while (res.next()) {
Amount = res.getDouble(1);
System.out.println(Amount);
boolean add = lst.add(Amount);

}
res.close();
}

} catch (Exception e) {
System.out.println(e.getMessage());
RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
rd.forward(request, response);
} finally {
request.setAttribute("data", lst);
RequestDispatcher rd = request.getRequestDispatcher("/responseTotal.jsp");
rd.forward(request, response);
lst.clear();
out.close();
}
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
public String getServletInfo() {
return "Short description";
}
}


and this is my jsp page where I could print the result of the query--
<%--
Document : DisplayRecord
Created on : 23 Jun, 2013, 12:57:59 PM
Author : Priya
--%>

<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
<title>View Cumulative Details</title>
</head>
<body>
<table>
<% Iterator itr;%>
<% List data = (List) request.getAttribute("data");
for (itr = data.iterator(); itr.hasNext();) {
%>
<tr>
<tr>
<td><strong>BKPL Total: </strong></td>
<td><span style="font-size:smaller; font-style:italic;"><% Double s = (Double) itr.next();%>
<%=s%></span></td>
</tr>



<%}%>
</tr>



</table>
</body>
</html>

I need to know how to run these multiple queries in the servlet and also how to print the result of those queries in the JSP page.

10 years ago

Balaji Vankadaru wrote:Please check your query line once




Query line works fine.
10 years ago
JSP

Carles Gasques wrote:Well then keep tracking back :-)

The problem could be the select

try to remove the question mark


Cheers,




Well that's not where the problem is. I cant get my afno passed to the servlet. the rest of the code is working fine. And the trace you wanted to do, its in the code in a different piece of code placed elsewhere and it works all fine. I can't pass the value of afno to servlet. Try running it in your IDE.
10 years ago
JSP