Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
Hi, I am new to java. I am trying to retrieving the data from access. I have a form(search data) in which i enter specialty and availday and i have a database in Ms-Access having four columns(Id,DoctName,Specialty,Availday). The thing I want is when i enter specialty and availday and click search button then it show result(data) having the specialty and availday that i want.
I have tried it to do but getting a syntax error.
 

String b=sp.getText();
String c=ad.getText();

st.executeQuery("select * from doctorinfo where speciality='"+b+"' AND Availability Day='"+c+"' ");
 

and please also help me in writing query(how to quote the syntax)
Thanks in advance.
Posted 13-Jun-13 8:48am
Comments
joshrduncan2012 at 13-Jun-13 13:57pm
   
What is the text of the syntax error that you are getting?
Anoop Kr Sharma at 13-Jun-13 14:08pm
   
java.sql.SQLException:syntax error(missing operator) in query expression
mgoad99 at 13-Jun-13 14:17pm
   
It may be that since Availability Day has a space you would need to use brackets [Availability Day]
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

st.executeQuery("select * from doctorinfo where Specialty = '" + b + "' AND [Availability Day]= '" + c + "'");
 
If your column name (Availbility day) have spaces in between them.Try like this.I hope this will help you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Column name's should not contain space in between. Here in your case, the exception is thrown due to space between Availability Day column. To prevent this, you can alter the table and put underscore(Availability_Day) in place of space or you can try this:
st.executeQuery("select * from doctorinfo where speciality='"+b+"' AND [Availability Day]='"+c+"' "); 
 
--Amit
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try like below...
st.executeQuery("select * from doctorinfo where Specialty = '" + b + "' AND Availday = '" + c + "'"); 
Make sure the column names (Specialty and Availday) and table name (doctorinfo) are correct.
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

It works. Thanks to all for your solution and Comments
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 320
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 184
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 14 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100