⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logondialog.java

📁 java 读写EXCEL文件的源码
💻 JAVA
字号:
/********************************************************************
 *
 * $RCSfile: LogonDialog.java,v $  $Revision: 1.1 $  $Date: 2003/09/22 08:06:24 $
 *
 * $Log: LogonDialog.java,v $
 * Revision 1.1  2003/09/22 08:06:24  icestone
 * init
 *
 *
 *
 **********************************************************************/
package pcdmupgradedata;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.net.*;
import java.util.*;
import com.borland.jbcl.layout.*;
import java.applet.Applet;
import java.io.*;
/**
*功能:登录数据库服务器对话框
*
*
*/

public class LogonDialog extends JDialog {
  private JPanel panel1 = new JPanel();
  private JPanel jPanel1 = new JPanel();
  private JPanel jPanel2 = new JPanel();
  private JTextField jTextField1 = new JTextField();
  private JPasswordField jTextField2 = new JPasswordField();
  private JLabel jLabel1 = new JLabel();
  private JLabel jLabel2 = new JLabel();
  private JButton jButton1 = new JButton();
  private JButton jButton2 = new JButton();

  private JTextField jTextField3 = new JTextField();
  private JTextField jTextField4 = new JTextField();
  private JLabel jLabel3 = new JLabel();
  private JLabel jLabel4 = new JLabel();
  private PaneLayout paneLayout1 = new PaneLayout();
  private PaneLayout paneLayout2 = new PaneLayout();

  Connection conn;
  static Connection conn1;
  private boolean DEBUG = false;

  public LogonDialog(Frame frame, String title, boolean modal) {
    super(frame, title, modal);
    try {
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage(System.getProperty("user.dir")+"//images//logo.gif"));
        jbInit();
        pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public LogonDialog() {
    this(new Frame(), "登录数据库", true);
  }
  private void jbInit() throws Exception {
    panel1.setLayout(paneLayout2);
    this.getContentPane().setLayout(paneLayout1);
    jPanel1.setBorder(BorderFactory.createEtchedBorder());
    jPanel1.setLayout(null);
    jPanel2.setBorder(BorderFactory.createEtchedBorder());
    jTextField1.setBounds(new Rectangle(84, 20, 187, 22));
    jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(KeyEvent e) {
        jTextField1_keyPressed(e);
      }
    });
    jTextField2.setBounds(new Rectangle(83, 48, 187, 22));
    jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(KeyEvent e) {
        jTextField2_keyPressed(e);
      }
    });
    jLabel1.setText("用户名");
    jLabel1.setBounds(new Rectangle(38, 22, 43, 18));
    jLabel2.setText("口令");
    jLabel2.setBounds(new Rectangle(40, 46, 42, 24));
    jButton1.setText("确定");
    jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(KeyEvent e) {
        jButton1_keyPressed(e);
      }
    });
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    jButton2.setText("返回");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton2_actionPerformed(e);
      }
    });
    jTextField3.setBounds(new Rectangle(82, 75, 49, 22));
    jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(KeyEvent e) {
        jTextField3_keyPressed(e);
      }
    });
    jTextField3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jTextField3_actionPerformed(e);
      }
    });
    jTextField4.setToolTipText("");
    jTextField4.setBounds(new Rectangle(181, 76, 89, 22));
    jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(KeyEvent e) {
        jTextField4_keyPressed(e);
      }
    });
    jLabel3.setText("SID");
    jLabel3.setBounds(new Rectangle(40, 77, 31, 18));
    jLabel4.setText("服务器IP");
    jLabel4.setBounds(new Rectangle(134, 78, 47, 18));
    if(RWConfig.readInstance()!=null)jTextField3.setText(RWConfig.readInstance());
    if(RWConfig.readIp()!=null)jTextField4.setText(RWConfig.readIp());
    getContentPane().add(panel1,  new PaneConstraints("panel1", "panel1", PaneConstraints.ROOT, 1.0f));
    jPanel1.add(jLabel1, null);
    jPanel1.add(jTextField1, null);
    jPanel1.add(jTextField2, null);
    jPanel1.add(jLabel2, null);
    jPanel1.add(jTextField3, null);
    jPanel1.add(jTextField4, null);
    jPanel1.add(jLabel4, null);
    jPanel1.add(jLabel3, null);
    jPanel2.add(jButton1, null);
    jPanel2.add(jButton2, null);
    panel1.add(jPanel2,  new PaneConstraints("jPanel2", "jPanel2", PaneConstraints.ROOT, 1.0f));
    panel1.add(jPanel1,  new PaneConstraints("jPanel1", "jPanel2", PaneConstraints.TOP, 0.6421053f));
  }
  /*连接数据库服务器*/
  private void ConnDataBase(){

        String user_name = jTextField1.getText();
        String pass = jTextField2.getText();
        String oInstance = jTextField3.getText();
        String oIP = jTextField4.getText();
   /*存在脚本文件路径的得到*/
      try
         {

             if (user_name.equals("")){
                  JOptionPane.showConfirmDialog(null, "请输入数据库超级用户名!", "警告",JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                  return;
             }else if(pass.equals("")){
                  JOptionPane.showConfirmDialog(null, "请输入数据库登录口令!", "警告", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                  return;
             }else if(oInstance.equals("")){
                  JOptionPane.showConfirmDialog(null, "请输入数据库实例名!", "警告",JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                  return;
             }else if(oIP.equals("")){
                  JOptionPane.showConfirmDialog(null, "请输入数据库服务器IP地址!", "警告", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                  return;
                 }//end if


             /*建立与数据库连接*/
             String oJdbc = "jdbc:oracle:thin:@" + oIP + ":1521:"+oInstance;
             Class.forName("oracle.jdbc.driver.OracleDriver");
             conn=DriverManager.getConnection (oJdbc, user_name, pass);
         }
         catch (java.sql.SQLException se)
         {
               JOptionPane.showConfirmDialog(null, "数据库操作错误\n"+se,"错误",JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
               return;
         }
         catch(ClassNotFoundException ce)
         {
               Debug.print("is wrong!"+ce);
               return;
         }

               /**判断数据库版本*/
          if(JudgeDBVersion.getNewVersion (conn)==false)
            {
               JOptionPane.showConfirmDialog(null, "数据库不是最新版本\n请将数据库更新至最近的2.2版本!", "提示",
                                                      JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                return;
             }

           this.dispose();
           if(JudgeDBVersion.getFlagNew(conn,true)==false)
                  insertMidTable(conn,Const.PD_MID);

           MoveDataGui Mdialog = new MoveDataGui(conn);
           Mdialog.setSize(653,510);

           Mdialog.setLocation((BaseGui.screenSize.width - BaseGui.frameSize.width) / 2-200,
                                        (BaseGui.screenSize.height - BaseGui.frameSize.height) / 2-200);
           Mdialog.show();
  }

  void jButton1_actionPerformed(ActionEvent e) {
    this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
    ConnDataBase();
    RWConfig.writeConfig(jTextField3.getText(),jTextField4.getText());
    this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

  }

  void jTextField3_actionPerformed(ActionEvent e) {

  }

  void jButton2_actionPerformed(ActionEvent e) {
        System.exit(0);
  }

  void jTextField4_keyPressed(KeyEvent e) {
     if(e.getKeyCode ()==KeyEvent.VK_ENTER)jButton1.requestFocus();

  }

  void jTextField3_keyPressed(KeyEvent e) {
     if(e.getKeyCode ()==KeyEvent.VK_ENTER)jTextField4.requestFocus();
  }

  void jTextField2_keyPressed(KeyEvent e) {
     if(e.getKeyCode ()==KeyEvent.VK_ENTER)jTextField3.requestFocus();
  }

  void jTextField1_keyPressed(KeyEvent e) {
     if(e.getKeyCode ()==KeyEvent.VK_ENTER)jTextField2.requestFocus();
  }

  void jButton1_keyPressed(KeyEvent e) {
    this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
    ConnDataBase();
    RWConfig.writeConfig(jTextField3.getText(),jTextField4.getText());
    this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  }

  private static void insertMidTable(Connection con,String midFile)
      {
       int i=0;
       String d_rdfile=null;

       try{
  	    Statement updateStatement = con.createStatement();

            LineNumberReader out1 = new LineNumberReader
                                   (new InputStreamReader
                                   (new FileInputStream(midFile)));


            while((d_rdfile=out1.readLine()) != null) {
Debug.print("is "+i+",=="+d_rdfile);
                updateStatement.executeUpdate(d_rdfile);
                i++;
               }//end while
           out1.close();
           updateStatement.close();
   	}//end try
        catch (java.sql.SQLException se){
           }
        catch ( FileNotFoundException fe) {
               JOptionPane.showConfirmDialog(null, "脚本文件丢失!"+fe, "错误", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
           }//end try
        catch ( IOException ioe) {
               System.err.println(ioe.toString());
          }
      }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -