读书人

数据还原,该怎么处理

发布时间: 2012-01-30 21:15:58 作者: rapoo

数据还原
我的代码: 可以系统说该数据库目前已有其他连接,故操作失败.
请问怎么去杀死或断开与数据库连接的操作?????public int restore() {
int a=0;
Connection con = null;
Statement sta = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); //加载驱动
con = DriverManager.getConnection(loginFrame.link.trim(), loginFrame.user.trim(), loginFrame.password.trim());
sta = con.createStatement();
sta.executeUpdate("restore database stock from stock") ;
}
catch (Exception e) {
a=1;
try {
sta.close();
con.close();
}
catch (SQLException e1) {
}
}
finally {
try {
sta.close();
con.close();
}
catch (SQLException e) {
a=1;
}
}
return a;
}

[解决办法]
断开的存储过程 代码中调用改过程即可~传的参数是你数据库名称

SQL code
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[killspid]GOSET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GOcreate  proc  killspid  (@dbname  varchar(20))  as  begin  declare  @sql  nvarchar(500),@temp varchar(1000)declare  @spid  int  set  @sql='declare  getspid  cursor  for    select  spid  from  sysprocesses  where  dbid=db_id('''+@dbname+''')'  exec  (@sql)  open  getspid  fetch  next  from  getspid  into  @spid  while  @@fetch_status =0begin    set @temp='kill  '+rtrim(@spid)  exec(@temp)fetch  next  from  getspid  into  @spid  end  close  getspid  deallocate  getspid  endGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO 

读书人网 >J2SE开发

热点推荐