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

📄 mysqlplusframe.java

📁 用JAVA写的数据库程序,Oracle的JDBC驱动程序,SqlServer的JDBC驱动程序,配置数据库连接
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
          ex.printStackTrace();
      }
      System.exit(0);
  }

  public void newDocument() {
      if (cfgMap.size() == 0) return;
      InternalFrame frame = new InternalFrame(this);
      if (!frame.isOpen()) return;
      frame.setVisible(true); //necessary as of kestrel
      desktop.add(frame);
      try {
          frame.setSelected(true);
          internalFrameMap.put(new Integer(frame.currFrameNumber),frame);
          setButtonEnable();
      } catch (java.beans.PropertyVetoException e) {}
  }

  public void openFile() {
      if (fileDialog == null) {
          fileDialog = new FileDialog(this);
      }
      fileDialog.setMode(FileDialog.LOAD);
      fileDialog.show();

      String file = fileDialog.getFile();
      if (file == null) {
          return;
      }
      String directory = fileDialog.getDirectory();
      File f = new File(directory, file);
      if (f.exists()) {
          Document doc  = ((InternalFrame)internalFrameMap.get(new Integer(activeWindow))).getTextDocument();
          try {
              doc.remove(0,doc.getLength());
          } catch (BadLocationException e) {e.printStackTrace();};
          Thread loader = new FileLoader(f, doc);
	  loader.start();
      }
  }

  public void saveFile() {
      if (fileDialog == null) {
	  fileDialog = new FileDialog(this);
      }
      fileDialog.setMode(FileDialog.SAVE);
      fileDialog.show();
      String file = fileDialog.getFile();
      if (file == null) {
          return;
      }
      String directory = fileDialog.getDirectory();
      File f = new File(directory, file);
      try {
          FileOutputStream fstrm = new FileOutputStream(f);
          Document doc  = ((InternalFrame)internalFrameMap.get(new Integer(activeWindow))).getTextDocument();
          fstrm.write(doc.getText(0,doc.getLength()).getBytes());
          fstrm.flush();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }

  public void configDB() {
      if (cfgDlg == null) {
          cfgDlg = new ConfigDBDlg(this,"Config DB...",cfgMap);
          Dimension dlgSize = cfgDlg.getPreferredSize();
          Dimension frmSize = getSize();
          Point loc = getLocation();
          cfgDlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                          (frmSize.height - dlgSize.height) / 2 + loc.y);
      }
      cfgDlg.show();
  }

  public void execute() {
      ((InternalFrame)internalFrameMap.get(new Integer(activeWindow))).executeQuery();
  }

  public void showHistoryList() {
      if (listDlg == null)
          listDlg = new HistoryListDlg(this);
      Dimension dlgSize = listDlg.getPreferredSize();
      Dimension frmSize = getSize();
      Point loc = getLocation();
      listDlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                      (frmSize.height - dlgSize.height) / 2 + loc.y);
      listDlg.setList(((InternalFrame)internalFrameMap.get(new Integer(activeWindow))).getCommandList());
      listDlg.show();
  }

  public void autoCommit() {
      InternalFrame frame = (InternalFrame)internalFrameMap.get(new Integer(activeWindow));
      frame.setAutoCommit();
      if ( frame.getAutoCommitflag() )
        ((JButton)toolBtnMap.get("commit")).setIcon(commitDownIcon);
      else
        ((JButton)toolBtnMap.get("commit")).setIcon(commitUpIcon);
  }

  public void restoreWindow() {
      desktop.getDesktopManager().minimizeFrame((InternalFrame)internalFrameMap.get(new Integer(activeWindow)));
  }

  private void helpBtn_actionPerformed(ActionEvent e) {
      AboutBox dlg = new AboutBox(this);
      Dimension dlgSize = dlg.getPreferredSize();
      Dimension frmSize = getSize();
      Point loc = getLocation();
      dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                      (frmSize.height - dlgSize.height) / 2 + loc.y);
      dlg.setModal(true);
      dlg.show();
  }

  public void setButtonEnable() {
      boolean enableFlag = true;
      if (internalFrameMap == null ||
          internalFrameMap.size() == 0)
          enableFlag = false;
      try {
          ((JButton)toolBtnMap.get("open")).setEnabled(enableFlag);
          ((JButton)toolBtnMap.get("save")).setEnabled(enableFlag);
          ((JButton)toolBtnMap.get("execute")).setEnabled(enableFlag);
          ((JButton)toolBtnMap.get("commit")).setIcon(commitUpIcon);
          ((JButton)toolBtnMap.get("commit")).setEnabled(enableFlag);
          ((JButton)toolBtnMap.get("history")).setEnabled(enableFlag);

          ((JMenuItem)menuMap.get("open")).setEnabled(enableFlag);
          ((JMenuItem)menuMap.get("save")).setEnabled(enableFlag);
          ((JMenuItem)menuMap.get("execute")).setEnabled(enableFlag);
          ((JMenuItem)menuMap.get("history")).setEnabled(enableFlag);
      } catch (Exception ex) {
          ex.printStackTrace();
      }

  }

  public void loadConfig() {
//alias.1=ITSDC_173
//username.1=its
//password.1=its
//serverURL.1=jdbc:oracle:thin:@123.123.123.173:1521:ITSDC
//driver.1=oracle.jdbc.driver.OracleDriver
//dbtype.1=oracle
      try {
   	  Properties props = new Properties();
          props.load( new java.io.FileInputStream("./cfg/config.properties"));
          cfgMap = new HashMap();
          int num = 1;
          while(true) {
              String alias     = props.getProperty("alias."+num);
              if (alias == null) break;
              String username  = props.getProperty("username."+num);
              String password  = props.getProperty("password."+num);
              String serverURL = props.getProperty("serverURL."+num);
              String driver    = props.getProperty("driver."+num);
              String dbType    = props.getProperty("dbtype."+num);
              alias = alias.toUpperCase();
              CfgStru cfg = new CfgStru(alias,username,password,serverURL,driver,dbType);
              cfgMap.put(alias,cfg);
              num++;
          }
      } catch (Exception e) {
	  e.printStackTrace();
      }
  }

  public void loadKeyWord() {
      try {
   	  Properties props = new Properties();
          props.load( new java.io.FileInputStream("./cfg/keyword.properties"));
          String sCommand  = props.getProperty("command");
          String sKeyword  = props.getProperty("keyword");
          String sFunction = props.getProperty("function");
          int count = 0, i = 0;
          String sSeparator = "~";
          if (sCommand != null) {
              StringTokenizer st = new StringTokenizer(sCommand,sSeparator);
              count = st.countTokens();
              if (count > 0) {
                  command = new String[count];
                  while(st.hasMoreTokens()) {
                      command[i++] = st.nextToken().toUpperCase();
                  }
              }
          }
          if (sKeyword != null) {
              StringTokenizer st = new StringTokenizer(sKeyword,sSeparator);
              count = st.countTokens();
              if (count > 0) {
                  keyWords = new String[count];
                  i = 0;
                  while(st.hasMoreTokens()) {
                      keyWords[i++] = st.nextToken().toUpperCase();
                  }
              }
          }
          if (sFunction != null) {
              StringTokenizer st = new StringTokenizer(sFunction,sSeparator);
              count = st.countTokens();
              if (count > 0) {
                  function = new String[count];
                  i = 0;
                  while(st.hasMoreTokens()) {
                      function[i++] = st.nextToken().toUpperCase();
                  }
              }
          }

//          File pFile = new File("./cfg/keyword.dat");
//          RandomAccessFile file = new RandomAccessFile(pFile,"r");
//          String s = file.readLine();
//          StringTokenizer st = new StringTokenizer(s,"~");
//          int count = st.countTokens();
//          keyWords = new String[count];
//          count = 0;
//          while(st.hasMoreTokens()) {
//             keyWords[count++] = st.nextToken();
//          }
      } catch (Exception e) {
	  e.printStackTrace();
      }
  }

  public HashMap getCfgMap() {
      return cfgMap;
  }

  class MyKeyAdapter extends KeyAdapter {
      public void keyPressed(KeyEvent e) {
        if ( KeyEvent.VK_F5 == e.getKeyCode())
            execute();
      }
  }

    /**
     * Thread to load a file into the text storage model
     */
    class FileLoader extends Thread {

	FileLoader(File f, Document doc) {
	    setPriority(4);
	    this.f = f;
	    this.doc = doc;
	}

        public void run() {
	    try {
		// try to start reading
		Reader in = new FileReader(f);
		char[] buff = new char[4096];
		int nch;
		while ((nch = in.read(buff, 0, buff.length)) != -1) {
		    doc.insertString(doc.getLength(), new String(buff, 0, nch), null);
		}
	    } catch (IOException e) {
		System.err.println(e.toString());
	    } catch (BadLocationException e) {
		System.err.println(e.getMessage());
	    }
	}
	Document doc;
	File f;
    }
}

class CfgStru {
    String alias,username,password,serverURL,driver,dbType;
    CfgStru(String alias,String username,
           String password,String serverURL,
           String driver,String dbType) {
           this.alias = alias;
           this.username  = username;
           this.password  = password;
           this.serverURL = serverURL;
           this.driver = driver;
           this.dbType = dbType;
    }
}

⌨️ 快捷键说明

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