|
呵呵,帮楼主粘贴代码如何?
package Mypackage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.sql.*;
import org.jibble.simpleftp.SimpleFTP;
import jcifs.smb.*;
public class BackupSql{
public static void main(String args[]){
String FileName = new String("2006111102");
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
try{
Class.forName(driver).newInstance();
System.out.println("load sqldrivice successfull!!");
}catch(Exception e)
{
System.out.println("Can't load!!");
}
try{
String dbURL="jdbc:microsoft:sqlserver://sqlserver's ip:1433;DatabaseName=databasename"; //the sqlserver'ip &the databasename
String userName="sa";
String userPwd="passwd"; //dbo'passwd
Connection con;
con=DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "backup database test_group_cef_test_db to disk = 'c:\\sun\\"+FileName+"' ";
PreparedStatement stmt = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt.execute();
System.out.println("backup successfull!!");
}catch(Exception e){
e.printStackTrace();
System.out.println("backup failed!!");
}
try{
SimpleFTP myftp = new SimpleFTP();
File fi = new File("D:\\TDbackup\\"+FileName);
RandomAccessFile getFile = new RandomAccessFile(fi,"r");
String ch;
myftp.connect("ftpserver'ip",21,"name","passwd"); //login the ftpserver
myftp.bin();
myftp.cwd("upload/sun");
System.out.println("uploading wait...");
BufferedReader in = new BufferedReader(new InputStreamReader(new SmbFileInputStream("smb://administrator:leadtone130@192.168.10.130/sun/"+FileName)));
while ((ch=in.readLine())!=null) {
getFile.writeBytes(ch);
}
myftp.stor(new File("D:\\TDbackup\\"+FileName));
System.out.println("upload successfull!!");
myftp.disconnect();
}catch (IOException ex){
ex.printStackTrace();
System.out.println("upload failed!!");
}
}
} |
|