sql2000 preparedStatement 查询语句出错

zzcwyu 2010-04-28 02:34:20
if(id==1)
table="student";
else if(id==2) table="wyu";
else if(id==3) table="outer_user";
else return flag;
String sql="select * from "+table+"where name=? and password=?"; //这样有错吗?
try {
con=new DatabaseCon().getCon();
pst=con.prepareStatement(sql);
pst.setString(1, user.getName()); //1,2,在数据库的类型是char
pst.setString(2, user.getPassword());

以下是出错信息
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第 1 行: '=' 附近有语法错误。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at zzc.meeting.handle.LogonDo.isExist(LogonDo.java:36)
at zzc.meeting.servlet.Logon.doPost(Logon.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
...全文
114 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu4545533 2010-04-28
  • 打赏
  • 举报
回复
表名和 where 之间没有空格隔开吧
zzcwyu 2010-04-28
  • 打赏
  • 举报
回复
晕死,想结贴也过要过段时间才行、
zzcwyu 2010-04-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 soli11722984 的回复:]
String sql="select * from "+table+"where name=? and password=?";

where 前面少个空格
[/Quote]
首先很感谢,其次我很自责,这错我以前似乎犯过,晕死。
soli11722984 2010-04-28
  • 打赏
  • 举报
回复
String sql="select * from "+table+"where name=? and password=?";

where 前面少个空格

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧