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

>
+
Etiketlenen Kullanıcılar

 
 
LinkBack Seçenekler Arama Stil
Prev önceki Mesaj   sonraki Mesaj Next
Alt 17 Eylül 2012, 09:35   #1
Çevrimdışı
Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
IF Ticaret Sayısı: (0)
IF Ticaret Yüzdesi:(%)
Java ile MySQL Backup Alma işlemi





Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir.




PHP Kod:   Kodu kopyalamak için üzerine çift tıklayın!
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...]

 
Alıntı ile Cevapla

 

Etiketler
alma, backup, ile, işlemi, java, mysql


Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir)
 

Yetkileriniz
Konu Acma Yetkiniz Yok
Cevap Yazma Yetkiniz Yok
Eklenti Yükleme Yetkiniz Yok
Mesajınızı Değiştirme Yetkiniz Yok

BB code is Açık
Smileler Açık
[IMG] Kodları Açık
HTML-Kodu Kapalı
Trackbacks are Kapalı
Pingbacks are Açık
Refbacks are Açık


Benzer Konular
Konu Konuyu Başlatan Forum Cevaplar Son Mesaj
NVIDIA'nın 40 milyar dolara ARM'yi satın alma işlemi iptal edildi CyBeR Teknoloji Dünyasından Son Haberler 1 08 Şubat 2022 19:46
NVIDIA'nın 40 milyar dolara ARM'yi satın alma işlemi iptal edilebilir CyBeR Teknoloji Dünyasından Son Haberler 3 27 Ocak 2022 13:10
Java ile MySQL: Basit Puan Sistemi Kaf_Dağı JavaScript 0 18 Mart 2015 15:06
Java tablo doldurma ve tablodan veri alma SeckiN JavaScript 0 04 Kasım 2014 15:56
Cpanel Full Backup Alma (Resimli Anlatım) Spartacus Whm-cPanel 2 11 Nisan 2012 15:38