IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası

IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası (https://www.ircforumlari.net/)
-   JavaScript (https://www.ircforumlari.net/javascript/)
-   -   Java ile MySQL Backup Alma işlemi (https://www.ircforumlari.net/javascript/504198-java-ile-mysql-backup-alma-islemi.html)

YazılımMimarı 17 Eylül 2012 09:35

Java ile MySQL Backup Alma işlemi
 
[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]



PHP- Kodu:

import org.apache.commons.io.FileUtils;
 public class 
dbasebackupdetailpanel extends javax.swing.JPanel {
 
JFileChooser fc = new JFileChooser();
 private 
boolean isConnected false;
 
Connection conn null;
 List 
tables null;
 
String urlpassworduname;
 
//backup butonu
 
private void btnBackupActionPerformed(java.awt.event.ActionEvent evt) {
 try {
 
fc.setDialogTitle("Create a file to BackUp database");
 
fc.setCurrentDirectory(fc.getCurrentDirectory());
 if (
fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
 
File file = new File(fc.getSelectedFile().getAbsolutePath() + ".sql");
 
String data null;
 if (
chkTables.isSelected() == false) {
 
data this.getData(tfHost.getText(), tfPort.getValue().toString(), tfUser.getText(), tfPassword.getText(), "dbFStation");
 } else {
 
data this.getData(tfHost.getText(), tfPort.getValue().toString(),  tfUser.getText(), tfPassword.getText(),     "dbFStation",cmbTables.getSelectedItem().toString());
 }
 
FileUtils.writeStringToFile(filedata);//avaible when import org.apache.commons.io.FileUtils;
 
xputils.showMessage("Backup Successfull");
 }
 } catch (
Exception e) {
 
xputils.showErrorMessage(e.toString());
 }}
 
//baglantı butonu
 
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {
 
//kontrol validasyonu
 
url "jdbc:mysql://" tfHost.getText() + ":" tfPort.getValue() + "/dbFstation";
 
uname tfUser.getText();
 
password tfPassword.getText();
 try {
 
conn DriverManager.getConnection(urlunamepassword);
 if (
conn != null) {
 
isConnected true;
 
this.btnBackup.setEnabled(true);
 
getTableNames(conn);
 
this.cmbTables.setModel(tablesModel());
 
xputils.showMessage("Connection was  Succesfull");
 } else {
 
this.btnBackup.setEnabled(false);
 
isConnected false;
 
xputils.showMessage("Connection was not Succesfull");
 }
 } catch (
SQLException ex) {
 
Logger.getLogger(dbasebackupdetailpanel.class.getName()).log(Level.SEVEREnullex);
 }}
 private 
int BUFFER 10485760;
 
//butun tabloların backup ını almak
 
private String getData(String hostString portString user,
 
String passwordString dbthrows Exception {
 
Process run Runtime.getRuntime().exec(
 
"mysqldump –host=" host " –port=" port +" –user=" user " –password=" password +    " " +                db);
 
InputStream in run.getInputStream();
 
BufferedReader br = new BufferedReader(new InputStreamReader(in));
 
StringBuffer content = new StringBuffer();
 
int count;
 
char[] cbuf = new char[BUFFER];
 while ((
count br.read(cbuf0BUFFER)) != -1) {
 
content.append(cbuf0count);
 }
 
br.close();
 
in.close();
 return 
content.toString();
 }
 
//bir tablonun backup ını almak
 
private String getData(String hostString portString user,
 
String passwordString dbString tablethrows Exception {
 
Process run Runtime.getRuntime().exec(
 
"mysqldump –host=" host " –port=" port +  " –user=" user "  –password=" password " " +                db "  " table);
 
InputStream in run.getInputStream();
 
BufferedReader br = new BufferedReader(new InputStreamReader(in));
 
StringBuffer content = new StringBuffer();
 
int count;
 
char[] cbuf = new char[BUFFER];
 while ((
count br.read(cbuf0BUFFER)) != -1) {
 
content.append(cbuf0count);
 }
 
br.close();
 
in.close();
 return 
content.toString();
 }
   
//db'den tablo adlarını almak
 
private void getTableNames(Connection con) {
 
String[] DB_TABLE_TYPES = {"TABLE"};
 
String COLUMN_NAME_TABLE_NAME "TABLE_NAME";
 
ResultSet rs null;
 try {
 
DatabaseMetaData meta conn.getMetaData();
 
rs meta.getTables(nullnullnullDB_TABLE_TYPES);
 if (
rs != null) {
 
tables = new ArrayList();
 while (
rs.next()) {
 
String tableName rs.getString(COLUMN_NAME_TABLE_NAME);
 if (
tableName != null) {
 
tables.add(tableName);
 }}}
 
con.close();
 } catch (
Exception e) {
 
e.printStackTrace();
 }}
 
//liste olarak tablo adlarını combobox içine doldurmak
 
public ComboBoxModel tablesModel() {
 
ComboBoxModel model;
 if (
tables == null || tables.size() <= 0) {
 
Object[] = new Object[1];
 
ComboBoxModel mo = new DefaultComboBoxModel(d);
 return 
mo;
 }
 
Object[] days = new Object[tables.size()];
 
int i 0;
 try {
 
ListIterator lg tables.listIterator();
 while (
lg.hasNext()) {
 
days[i] = tables.get(i);
 
1;
 }
 } catch (
Exception ex) {
 
System.out.println("error occured " ex.toString());
 }
 
model = new DefaultComboBoxModel(days);
 return 
model;
 } 

[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]


Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 16:32.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
Copyright ©2004 - 2025 IRCForumlari.Net Sparhawk