当前位置: 技术问答>java相关
高分求解一个关于数据库的问题
来源: 互联网 发布时间:2015-02-09
本文导语: 我想在一个结果集中得到三个数值:某种型号设备的总数,各个状态的数量(共两个状态)。我写了下面的语句: sql="select count(*) from "+queryCategory+" as a right join Equipment as b on a.EquipmentID=b.EquipmentID where (a.Model...
我想在一个结果集中得到三个数值:某种型号设备的总数,各个状态的数量(共两个状态)。我写了下面的语句:
sql="select count(*) from "+queryCategory+" as a right join Equipment as b on a.EquipmentID=b.EquipmentID where (a.Model='"+queryModel+"')"+" and "+sqlQuery+
" union all select count(*) from "+queryCategory+" as a right join Equipment as b on a.EquipmentID=b.EquipmentID where (a.Model='"+queryModel+"') and "+sqlQuery+" and b.Using='在线' "+
" union all select count(*) from "+queryCategory+" as a right join Equipment as b on a.EquipmentID=b.EquipmentID where (a.Model='"+queryModel+"') and "+sqlQuery+" and b.Using='离线' ";
其中queryCategory是在查询窗口中得到的某种设备名,它有对应的表;queryModel则是某种具体型号。但是在调试过程中出现以下例外:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server](s.W 'as' D?碚?
我百思不得其解,还请各位大侠支招
又:上面的sql语句在查询分析器中能执行,得到的结果是三行一列的表
sql="select count(*) from "+queryCategory+" as a right join Equipment as b on a.EquipmentID=b.EquipmentID where (a.Model='"+queryModel+"')"+" and "+sqlQuery+
" union all select count(*) from "+queryCategory+" as a right join Equipment as b on a.EquipmentID=b.EquipmentID where (a.Model='"+queryModel+"') and "+sqlQuery+" and b.Using='在线' "+
" union all select count(*) from "+queryCategory+" as a right join Equipment as b on a.EquipmentID=b.EquipmentID where (a.Model='"+queryModel+"') and "+sqlQuery+" and b.Using='离线' ";
其中queryCategory是在查询窗口中得到的某种设备名,它有对应的表;queryModel则是某种具体型号。但是在调试过程中出现以下例外:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server](s.W 'as' D?碚?
我百思不得其解,还请各位大侠支招
又:上面的sql语句在查询分析器中能执行,得到的结果是三行一列的表
|
有可能是中文问题,你查询的语句当中是不是有汉字?SQL Server的JDBC我没有用过,我用过Oracle没有这个问题,MYSQL有中文问题。