473,799 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error in mysql query(syntax)

283 Contributor
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.expendit ure_code,5), expenditure_typ e' 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 1869
amitpatel66
2,367 Recognized Expert Top Contributor
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 Contributor
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 Recognized Expert Expert
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 MVP
and in Java always compare strings using the .equals method.
== compares references.
Oct 9 '07 #5
ajos
283 Contributor
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...wha t 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 MVP
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 Contributor
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">O utdoor</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
2107
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 reconiliation of debits and credits. Say you have a table / list that is 1000s of lines long. These could be either debits or credits. Then imagine you know that a certain
3
16253
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 strange error. In your experience, where I should looking to find the real error? Surely the sintax of glut is correct... gcc.exe -c glut_bitmap.c -o glut_bitmap.o -I"C:/Dev-Cpp/include" -I"../../include" -D__GNUWIN32__ -W -DWIN32 -DNDEBUG...
8
46199
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 where the inital " started? I find myself adding /* */ blocks or cutting/pasting sections of code out in order to find where the error occured. Wouldn't it it be nice if the warning message included the line in teh source where the initial quote ...
36
8012
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 shortcomings will soon become apparent. I am developing an estimating construction system, using PHP5 and MySQL 5.0.24a with Ubuntu. I have a main "projects" file, and 2 detail files, one for piping and one for equipment. Each of these files will have...
3
6951
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 offending line, but being amateur, I don't know where. I've tried putting one in several places, to no avail. Clearly, to solve this in a smaller period than a week I need someone with more skill to help out. Heh heh. The error is: Parse error:...
1
4893
by: sheenrose | last post by:
<? $uname = $_REQUEST; $pass = $_REQUEST; /*Connecting, selecting database */ $LogStatus = 0; $link = mysql_connect("localhost","root","kushal") or die();
21
2780
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! dim conn as adodb.connection dim strsql as string strsql="update regdetails set title= ' " & me.title.value & " ' , surname= " " & me.surname.value & " ', firstname= ' " & me.firstname.value & " ' where regnumber= ' " & me.regnumberdisplay.value...
2
3246
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 T_VARIABLE or T_NUM_STRING in /var/www/html/inventoryControl/supplier.php on line 26 (line number changed to match code tags) The code is as follows: // get a supplier using the supplier id
1
8909
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 location; Finally a bulleted list of all the rules you have to apply to your script to completely and fully transfer /any/ sqlite schema dump to a MySQL one. For this I need your help; I'll start with the popular few, anyone notice any other difference,...
14
5511
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 all the rows which have the corresponding state. I am getting this 'Parse error: syntax error, unexpected T_STRING in /home/attorney/public_html/' on line 13 <? $username="XXXXXXXX"; $password="XXXXXX"; $database="XXXXXXXX";
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.