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) 展开
{
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) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |