String fd= "D:\football2007.bak ";
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
Connection dbcon=DriverManager.getConnection( "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=master ", "sa ", " ");
//杀掉sql进程
Statement st=dbcon.createStatement();
ResultSet res=st.executeQuery( "select spid from master..sysprocesses where dbid=db_id( 'football2007 ') ");
while(res.next()){
String sqll= "kill "+ " "+res.getInt(1);
Statement stq=dbcon.createStatement();
stq.executeQuery(sqll);
}
Statement stat=dbcon.createStatement();
ResultSet result=stat.executeQuery( "restore database football2007 from disk= ' "+fd+ " ' ");
}
catch (Exception e){
out.println(e);
}
用jsp和ms sql数据库 还原时 报错:No ResultSet set was produced.
请告诉我是哪部分写错了,或者应该怎么编写?
------解决方案--------------------
把错误信息贴出来
------解决方案--------------------
ResultSet result=stat.executeQuery( "restore database football2007 from disk= ' "+fd+ " ' ");
}
这里有问题
还原数据库不应该用stat.executeQuery你可以这样做试试
PreparedStatement stat=conn.prepareStatement(restore database football2007 from disk=?);
stat.setString(1,fd);
stat.executeUpdate();
stat.close();
------解决方案--------------------
ResultSet result=stat.executeQuery( "restore database football2007 from disk= ' "+fd+ " ' ");
这条错了
restore database 根本不会返回ResultSet,你还用ResultSet去接,当然错了。
直接写 stat.executeQuery( "restore database football2007 from disk= ' "+fd+ " ' "); 就是了。