473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error in mysql query(syntax)

283 100+
hi friends,
i have a problem in mysql query..when i click on submit the values get enterred but i get a
SQLException
SQLState:42000
Message: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 ') GROUP BY left(a.expenditure_code,5), expenditure_type' at line 1
Vendor:1064
ever since i did some changes in my code(earlier i was getting a null pointer exception).my query goes like this-->
Expand|Select|Wrap|Line Numbers
  1. String s2 = "SELECT sum(paid_amt), left(a.expenditure_code,5), expenditure_type FROM expenditure_requisition_detail AS a, Publicity_Head_Master AS b WHERE a.expenditure_code = b.expenditure_code and req_code in (SELECT Req_Code FROM Expenditure_Requisition_Master WHERE ";
  2.             s2 = s2 + s3 + ") GROUP BY left(a.expenditure_code,5), expenditure_type";
  3.  
can someone please tell me where is the syntax error?
thanks in advance
regards,
ajos
Oct 9 '07 #1
7 1850
amitpatel66
2,367 Expert 2GB
hi friends,
i have a problem in mysql query..when i click on submit the values get enterred but i get a

ever since i did some changes in my code(earlier i was getting a null pointer exception).my query goes like this-->
Expand|Select|Wrap|Line Numbers
  1. String s2 = "SELECT sum(paid_amt), left(a.expenditure_code,5), expenditure_type FROM expenditure_requisition_detail AS a, Publicity_Head_Master AS b WHERE a.expenditure_code = b.expenditure_code and req_code in (SELECT Req_Code FROM Expenditure_Requisition_Master WHERE ";
  2.             s2 = s2 + s3 + ") GROUP BY left(a.expenditure_code,5), expenditure_type";
  3.  
can someone please tell me where is the syntax error?
thanks in advance
regards,
ajos

Please POST the value of s3 for better understanding.
Oct 9 '07 #2
ajos
283 100+
Please POST the value of s3 for better understanding.
thanks for the reply amitpatel66,
well its a conditional check if i can say...ok here goes..
Expand|Select|Wrap|Line Numbers
  1. s3 = s3 + "Branch = '" + s5 + "' ";
  2.         s4 = "Y";
  3.         if(!s6.equals("0"))
  4.         {
  5.             if(s4 == "Y")
  6.                 s3 = s3 + " AND ";
  7.             s3 = s3 + "cost_Center = '" + s6 + "'";
  8.             s4 = "Y";
  9.         }
  10.         if(s7.equals("0"))
  11.         {
  12.             System.out.print("");
  13.         } else
  14.         {
  15.             if(s4 == "Y")
  16.                 s3 = s3 + " AND ";
  17.             s3 = s3 + "publicity_Code = " + s7;
  18.             s4 = "Y";
  19.         }
  20.         if(s8.length() > 0)
  21.         {
  22.             if(s4 == "Y")
  23.                 s3 = s3 + " AND ";
  24.             s3 = s3 + "Req_Date BETWEEN #" + s8 + "# AND #" + s9 + "#";
  25.             s4 = "Y";
  26.         }
  27.         String s = "";
  28.         String s1 = "";
  29.  
hope u got it
regards,
ajos
Oct 9 '07 #3
Atli
5,058 Expert 4TB
Hi.

It looks to me like you are trying to add two strings using the "+" operator.

In PHP you should use a period "." when adding two strings:
Expand|Select|Wrap|Line Numbers
  1. $str = "First " . "Second";
  2.  
  3. $str2 = $str . " Third";
  4.  
  5. $str2 .= " Fourth";
  6.  
  7. echo $str2;
  8. # Prints: First Second Third Fourht
  9.  
Edit:
Looking closer at your code, I see you are not using PHP... The way you did it works in Java, as far as I know... So just ignore this post :)
Oct 9 '07 #4
r035198x
13,262 8TB
and in Java always compare strings using the .equals method.
== compares references.
Oct 9 '07 #5
ajos
283 100+
and in Java always compare strings using the .equals method.
== compares references.
thanks guys for all the replies.
hey r035198x,
i previously was comparing the strings using the .equals method, but it was giving me null pointer exceptions,so the change but ever since this change i am getting this mysql state 42000 exception...what should i do to avoid this exception and null pointer exception also.thanks,
ok guys i have eliminated the null pointer exception by making some changes here--->
Expand|Select|Wrap|Line Numbers
  1. String s6 = httpservletrequest.getParameter("cost_Center");
  2. String s7 = httpservletrequest.getParameter("publicity_Code");
  3.  
here i have made the 'C' capital letter.but the sql exception stays.please help me with my sql query.thanks
regards,
ajos
Oct 10 '07 #6
r035198x
13,262 8TB
Please post two things:
1.) The full exception trace that was thrown
2.) The full mysql query that you had passed to the MySQL engine. (You can get this by doing a println of the String before executing the sql)
Oct 10 '07 #7
ajos
283 100+
friends, problem solved!!!! hurray(this joy is temporary though!)
actually i had something like this in my jsp page-->
[HTML]
<html:option value="0"></html:option>
<html:option value="41601">Outdoor</html:option>
......and so on
[/HTML]

and in my class
Expand|Select|Wrap|Line Numbers
  1. if(!s6.equals("0"))
  2.         {
  3.             if(s4 == "Y")
  4.                 s3 = s3 + " AND ";
  5.             s3 = s3 + "cost_center = '" + s6 + "'";
  6.             s4 = "Y";
  7.             System.out.println("enterring s6");
  8.         }
  9. and so on....
  10.  
i forgot to put the 0 in my <html:option> and so the compiler wasnt getting the value 0 and hence the exception! phew....i simple word can cause such problems...i should be getting a kick for this in my back side..haha:)
regards,
ajos
Oct 10 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: seanseaghan | last post by:
New to this group, so greetings all! I am trying to develop query syntax in Access 2000 to accomplish the following: Imagine you are in an accounting dept. and you are working on a...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
8
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine...
36
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My...
3
by: SilvaZodiac | last post by:
Hi everyone, I'm still rather new to PHP code, and I have a syntax error. I've tried several different solutions, but it won't fix. It seems to suggest that I need a new bracket somewhere in the...
1
by: sheenrose | last post by:
<? $uname = $_REQUEST; $pass = $_REQUEST; /*Connecting, selecting database */ $LogStatus = 0; $link = mysql_connect("localhost","root","kushal") or die();
21
by: missflorenceokosun | last post by:
hi, am florence. i keep having a runtime error stating error in update query syntax. i have looked through my code over and over gain and seem to find no flaw. i need you guys to help me out! ...
2
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or...
1
dlite922
by: dlite922 | last post by:
I'm trying to convert an SQLITE database to MySQL syntax and it seems every resource I find on google is only half complete. I want to create this thread to sum them all up in one central...
14
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.