java中的SQL语法错误 [英] Sql syntax error in java

查看:182
本文介绍了java中的SQL语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是java新手。我正在尝试从访问中检索数据。我有一个表格(搜索数据),我进入专业和availday,我有一个数据库在Ms-Access有四列(Id,DoctName,专业,Availday)。我想要的是当我进入专业和availday并点击搜索按钮然后它显示具有我想要的专业和availday的结果(数据)。

我试过它但是得到语法错误。





字符串b = sp.getText();< br /> 
字符串c = ad.getText();



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





也请帮我写一下查询(如何引用语法)

提前谢谢。

解决方案

st.executeQuery(select * from doctorinfo where Specialty ='+ b +'和[可用日] ='+ c +');



如果您的专栏名称(可用日期)之间有空格。请尝试这样。我希望这对您有所帮助。


< blockquote>列名称之间不应包含空格。在您的情况下,由于可用性日列之间的空格而引发异常。为了防止这种情况,您可以更改表格并放置下划线( Availability_Day )代替空格,或者您可以尝试:

 st.executeQuery(  select * from doctorinfo,其中special =' + b +  'AND [可用日期] =' + c +  '); 





- Amit


尝试如下......

 st.executeQuery(  select * from doctorinfo where Specialty =' + b +  'AND Availday =' + c + < span class =code-string> '); 



确保列名称(专业 Availday )和表名( doctorinfo )是正确的。


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();<br />
      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.

解决方案

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.


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


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.


这篇关于java中的SQL语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆