Java程序执行对SQL Server 2008数据库的备份与恢复时出现错误
Java程序执行对SQLServer2008数据库的备份与恢复时出现nosuitabledriverfoundforjdbc:jtds:sqlserver://local...
Java程序执行对SQL Server 2008数据库的备份与恢复时出现no suitable driver found for jdbc:jtds:sqlserver://localhost:1433/master 哪位大神能解答一下
代码:
----------------------------
File backupFile=new File(path);
String sql="backup database db_myerp to DISK='"+backupFile.getAbsolutePath()+"'";
try {
Dao.restoreOrBackup(sql);
} catch (Exception e1) {
e1.printStackTrace();
String message = e1.getMessage();
int index = message.lastIndexOf(']');
message=message.substring(index+1);
JOptionPane.showMessageDialog(BackupAndRestore.this, message);
return;
}
----------------------------
public static int restoreOrBackup(String sql) throws Exception {
int rs = 0;
if (conn != null) {
conn.close();
}
// 连接到系统数据库
conn = DriverManager.getConnection(
"jdbc:jtds:sqlserver://localhost:1433/master", dbUser,
dbPwd);
Statement stmt = conn.createStatement();
// 定义单用户连接模式的SQL语句
String single = "alter database db_myerp set single_user"
+ " with rollback immediate " + sql;
// 执行数据库备份或恢复的SQL语句
rs = stmt.executeUpdate(single);
stmt.close();
conn.close(); // 关闭数据库连接
// 恢复原有数据库连接
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
return rs;
}
protected static String dbClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
protected static String dbUrl = "jdbc:sqlserver://localhost:1433;DatabaseName=db_myerp"; 展开
代码:
----------------------------
File backupFile=new File(path);
String sql="backup database db_myerp to DISK='"+backupFile.getAbsolutePath()+"'";
try {
Dao.restoreOrBackup(sql);
} catch (Exception e1) {
e1.printStackTrace();
String message = e1.getMessage();
int index = message.lastIndexOf(']');
message=message.substring(index+1);
JOptionPane.showMessageDialog(BackupAndRestore.this, message);
return;
}
----------------------------
public static int restoreOrBackup(String sql) throws Exception {
int rs = 0;
if (conn != null) {
conn.close();
}
// 连接到系统数据库
conn = DriverManager.getConnection(
"jdbc:jtds:sqlserver://localhost:1433/master", dbUser,
dbPwd);
Statement stmt = conn.createStatement();
// 定义单用户连接模式的SQL语句
String single = "alter database db_myerp set single_user"
+ " with rollback immediate " + sql;
// 执行数据库备份或恢复的SQL语句
rs = stmt.executeUpdate(single);
stmt.close();
conn.close(); // 关闭数据库连接
// 恢复原有数据库连接
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
return rs;
}
protected static String dbClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
protected static String dbUrl = "jdbc:sqlserver://localhost:1433;DatabaseName=db_myerp"; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询