異常 Hibernate資料庫恢復錯誤

2022-03-19 02:50:45 字數 746 閱讀 4289

環境及情況說明

環境:sqlserver2008,struts1.2和hibernate;

1、使用hibernate獲得資料庫的連線,在hibernate中 使用的都是transaction事務管理器,這個是乙個事務,在其中呼叫備份資料庫語句的時候會出現異常

不能在事務內部執行備份或還原操作

的警告;

解決方法:使用下列語句獲得連線,

class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver");

if (conn==null||conn.isclosed())

2、現在可以對資料庫進行備份操作,但是不能進行恢復操作,因為恢復需要獨佔資料庫使用權,

解決方法:使用下列sql語句,建立preparedstatement

string sql = "alter database dms set offline with rollback immediate " +         //斷開資料庫的所有連線

"use master restore database ? from disk=? with replace " +                    //恢復資料庫

"alter database dms set online with rollback immediate";            //恢復資料庫的所有連線

現在既可以備份資料庫,又可以恢復資料庫啦~~~

異常 Hibernate資料庫恢復錯誤

環境及情況說明 環境 sqlserver2008,struts1.2和hibernate 1 使用hibernate獲得資料庫的連線,在hibernate中 使用的都是transaction事務管理器,這個是乙個事務,在其中呼叫備份資料庫語句的時候會出現異常 不能在事務內部執行備份或還原操作 的警告...

hibernate資料庫連線

size 12 昨天學習hibernate一天,使用sqlserver2000資料庫,今天早上嘗試了一下mysql資料庫,發現大同小異,不過還是記在這裡吧,好記性不如個爛鍵盤 size color blue 使用mysql資料庫時候的hibernate.cfg.xml檔案內容 color color...

簡單Hibernate資料庫操作

引hibernate中的session,session大多對實體進行操作 publicclassnewdao 資料查詢 查詢所有資料 publiclist selectnew 根據 id查詢該 id的資訊 publicnews selectone string id 資料更新 新增資料 從 acti...