mysql數據庫__Jdbc直接操作__PreparedStatement__數據庫備份
阿新 • • 發佈:2017-10-08
serve stat lock oca execute ted sql數據庫 set backup
一、代碼如下
private void BackupDatabase() { // TODO Auto-generated method stub java.sql.PreparedStatement ps = null; java.sql.Connection cn = null; ResultSet rs = null; try { // Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Class.forName("com.mysql.jdbc.Driver").newInstance(); cn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/learn?user=root&password=&useUnicode=true&characterEncoding=UTF8"); ps = cn.prepareStatement("backup database learn to disk=‘d:/12345.bak‘"); int i= ps.executeUpdate(); System.out.println(i); if(i>=1) { System.out.println("數據庫備份:成功"); }else { System.out.println("數據庫備份:失敗"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { ps.close(); cn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
mysql數據庫__Jdbc直接操作__PreparedStatement__數據庫備份