Cezanne Khan

Greenhorn
+ Follow
since Aug 20, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Cezanne Khan

Well, i have read about request dispatcher. Will it be feasible in this situation? If so, how'll we achieve such functionality?
12 years ago

Bear Bibeault wrote:Your servlet shouldn't be generating the output. After it does the computations, it should forward to a JSP to create the display.

See this article for details on how to properly structure web applications.



But the problem is that the servlet is displaying the chart after taking values from a jsp, and i want to include that chart (whether as an image or the servlet is passed to another jsp, and that jsp is included in the previous jsp). How i am gonna achieve this?
12 years ago
Hi,

I have a problem that i have a servlet and a jsp page. This jsp page sends the parameters to servlet which then generates a graph. But the problem is that the graph is being displayed in the servlet and i have to go back to the jsp page to select other values. What i want is that when user selects a value and click on the button, then instead of displaying the chart in servlet, it should display in the jsp page. How can i achieve such functionality?
12 years ago
The problem is solved, thanks Vishal and Paul, i found the solution.

Vishal Shaw wrote:

select Country_Name, 'y1964' from sadm where Series_Name= 'Agricultural machinery tractors' order by 'y1964' desc



Did you tried running theis exact query in your mysql directly? Also, is y1964 your column name? Then did you realized, that you have quotes around it



Yes, i did that, but what i am doing is that passing two values from jsp to a servlet, which then take these values and generate graph. y1964 is the name of a column which is in my database. And i have columns from y1960 to y2011. When a user select a year and any indicator say "Agricultural machinery tractors", then these values are passed to a servlet. I have run the same query in mysql, but i have not given the quotes around it as, mysql doesn't accept quotes, it will treat it something else, but in java, when i wrote the query it is necessary to put quotes, otherwise it give errors.

The sql query is:



And the query written in java is:



where YearName is the year, which in this case is y1964, and SeriesName is the "Agricultural machinery tractors". Both of then have been selected by the user.

Vishal Shaw wrote:Hi,

Paul Clapham wrote:
Okay. You're a troll, then. No more answers from me.


why? i really need help.



Basically, from the thread , Paul asked you several times to do this:


But you constantly, ignored this. He is right, if you don't show us your exact query , how can you expect us to solve them. And yes, the error message clearly suggests there is an error in your sql syntax

Regards,
Vishal




My apologize. I am new to this forum and don't know much about it. Secondly, i have done the way you and Paul said,

This is the System.out.println(sql); result which is shown on the console.

.
I just changed the query, because JDBCPieDataSet require 2 columns. Now the query is like



When i execute it i got the error, "JDBCPieDataset - unknown data type". What should i do?

Cezanne Khan wrote:

Paul Clapham wrote:Okay. You're a troll, then. No more answers from me.



why? i really need help.



Paul Clapham wrote:Okay. You're a troll, then. No more answers from me.



why? i really need help.

Paul Clapham wrote:It might be a good idea if you posted that exact SQL statement here. Somebody might see a problem with it.

(Notice that the "Code" button which you use to format code in the forum has an "SQL" option in the drop-down to the left of it, which makes SQL easier to read when it's posted here.)



"select y1960, y1961, y1962, y1963, y1964, y1965, y1966, y1967, y1968, y1969, y1970, y1971, y1972, y1973, y1974, y1975, y1976, y1977, y1978, y1979, y1980, y1981, y1982, y1983, y1984, y1985, y1986, y1987, y1988, y1989, y1990, y1991, y1992, y1993, y1994, y1995, y1996, y1997, y1998, y1999, y2000, y2001, y2002, y2003, y2004, y2005, y2006, y2007, y2008, y2009, y2010, y2011 from sadm where Country_Name= '" + CountryName + "' and Series_Name= '" + SeriesName + "'";

Here it is.

chris webster wrote:As Paul says, print out the exact SQL statement that is actually generated and which actually causes the error.

Then copy this statement and execute it via your database's SQL query interface (i.e. not JFreeChart or Java) so you can see if the query works without multiple layers of Java between your SQL string and the database.

If it still doesn't work, then change it and test it via your database's SQL query interface until it's working correctly.

Then put the corrected SQL code back into your Java and test it again.

Watch out for special characters (e.g. single quotes, ampersands etc) inside the strings you use for Country and Series, because these may cause problems when your SQL reaches the database. If possible, test that the query executes successfully for every possible value of Country/Series.



Yep, i have done that. Working perfectly with database, but not here.

Paul Clapham wrote:I say, if the package requires you to generate SQL in the form of a string, then do that.



Already used the Strings, but not working

Paul Clapham wrote:By the way: Generating SQL in that way is likely to lead to problems. First of all you have to make sure your quotes match, and you have the right kind of quotes in the right place. And then even if they do match, having more quotes in the string data which you concatenate together can make your quotes be unbalanced again. And also if your string data came from user input, it can be used for SQL injection attacks which can damage your database.

The usual advice here is to use a PreparedStatement, rather than building your SQL from strings like that. But I see that you are working with some kind of utility code which prefers those error-prone strings. So you should look at it to see if it will accept a PreparedStatement, perhaps in some other overloaded method. If so, you should switch to using that other method.



Right, my previous preference was to use the PreparedStatement, but the problem here is that i'm not using the conventional way of connection for connecting to database, rather i am using a library called JFreeChart, and you can see that i have passed the connection parameter to the JDBCPieDataSet. The problem here is that this method doesn't have a PreparedStatement, so that's why i preferred using Strings. What do you say?

Paul Clapham wrote:Yes. The error message tells you that there's something wrong with your SQL. So look at your SQL.

And no, that bunch of Java code is not your SQL. It's a line of code which produces your SQL. So don't look at the Java code, look at the string which it produces. I already showed you how to look at that string.



Will you please correct it, because i have tried a lot by changing the parameters and quotes, by changing its syntax, but still got the error.