1. 程式人生 > >資訊管理系統開發遇到的問題

資訊管理系統開發遇到的問題

加this和不加this的區別

    this是指的物件本身,通過this可以呼叫本物件擁有的所有方法和屬性,當然不加this也可以呼叫。

一般用this的情況:

   1.當局部變數與成員變數相同名時,例如 this,x = x;this.x 是個成員變數,而x是個區域性變數

 2.在myeclipse下用this可以提示後面的方法或者成員變數

    3. 在內部類或匿名內部類中使用this來指向內部類本身
pingpuItem.addActionListener(new ActionListener() {

   @Override
   public void actionPerformed
(ActionEvent e) { JInternalFrame[] allFrames = desktopPanel.getAllFrames(); int x = 0 ; int y = 0 ; for(JInternalFrame frame : allFrames){ frame.setLocation(x, y); try { frame.setSelected(true
); } catch (PropertyVetoException e1) { e1.printStackTrace(); } int frameH = frame.getPreferredSize().height ; int panelH = frame.getContentPane().getHeight(); int
fSpace = frameH - panelH ; x += fSpace ; y += fSpace ; if(x + getWidth()/2 > desktopPanel.getWidth()) x = 0 ; if(y + getHeight()/2 > desktopPanel.getHeight()) y = 0 ; } } }); 上面的getWidth()不加this指的是呼叫外部類ToolBar的函式,加this的話指的是匿名類ActionListener中的函式 4. 將類本省作為引數傳遞
    private JMenu getChuang_kouMenu() {
        if(chuang_kouMenu == null ){
            chuang_kouMenu = new JMenu("視窗");
            chuang_kouMenu.setMnemonic(KeyEvent.VK_W);
            chuang_kouMenu.add(getPingpuItem());//開啟專案時就建立了選單項
            chuang_kouMenu.addMenuListener(new MenuListener() {

                @Override
                public void menuSelected(MenuEvent e) {

                    //chuang_kouMenu.removeAll();
                    //System.out.println("載入item");
                    chuang_kouMenu.add(getPingpuItem());//動態載入選單項
                    chuang_kouMenu.add(getClassAllItem());
                    chuang_kouMenu.add(getAllIconItem());
                    chuang_kouMenu.add(getAllResumeItem());

                }

連線池資源關閉問題

這裡寫圖片描述
在進行第三次新增的時候,發現軟體卡住了,後來發現是連線池的問題,連線池每次連線都沒有釋放連線,達到最大連線數就出現了問題,因此一定要關閉資源!!
還有要注意關閉順序,還有如果先關閉Connection,ResultSet的物件是不能使用的

if判斷下如果不止一條語句一定要加括號!!

在往資料庫中插入時出現
Duplicate entry ‘10’ for key ‘PRIMARY’ ,10是在id那一列,每次去id最大值然後加1插入新行,當插入第10行時,每次取之前最大id即max(id)都是9,是因為型別是varchar型別,改為int型別即可,注意
在取值的時候,如果還用rs.getString(1)會自動將int轉化為String型別取出