Java JDBC 创建临时表,插入数据,然后查询,没有返回结果集

publicbooleancheckCodeRepeat(List<String>codelist){SimpleDateFormatdateFormat=newSimp... public boolean checkCodeRepeat(List<String> codelist)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String now = dateFormat.format(new Date());
String table = "#"+"temp"+now;

String sql = "create table "+table+"(w_code varchar(20)) ";

for (int i = 0; i < codelist.size(); i++) {
sql = sql + "insert into "+table+" values('"+codelist.get(i)+"') ";
}

boolean flag = false;
try {
conn = this.getConnection();
sql = sql + "select count(*) from "+table+" where w_code in (select w_code from info) or w_code in (select m_code from info)";
System.out.println(sql);
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if(rs.next())
{
int result = rs.getInt(1);
if(result == 0)
{
flag = true;
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
finally
{
this.closeAll(conn, ps, rs);
}
return flag;
}

com.microsoft.sqlserver.jdbc.SQLServerException: 该语句没有返回结果集。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)

at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
at dao.InfoDao.checkCodeRepeat(InfoDao.java:594)
展开
 我来答
老男孩TD
2014-08-09
知道答主
回答量:11
采纳率:0%
帮助的人:5.9万
展开全部
看下数据库里面有信息不,如果没有,那就是插入时没有commit,数据丢失了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式