2016-01-04 12 views
-1

發帖 - 後,我安裝了MySQL驅動 被剷除一個錯誤,但那麼這一次發生不同的錯誤的MySQL

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
    Communications lin failure. 
    The last packet sent successfully to the server was 0 milliseconds ago. 
    The driver has not received any packets from the server. 

有編譯過程中沒有問題點擊所以這裏添加按鈕,只有當是代碼它:

package mainquiz; 
import java.sql.*; 
import javax.swing.*; 
import java.awt.Toolkit; 
import java.awt.event.KeyEvent; 

public class AddStudent extends javax.swing.JFrame { 
public AddStudent() { 
    initComponents(); 
} 

@SuppressWarnings("unchecked") 
// <editor-fold defaultstate="collapsed" desc="Generated Code">       
private void initComponents() { 

    jLabel1 = new javax.swing.JLabel(); 
    jLabel2 = new javax.swing.JLabel(); 
    jLabel3 = new javax.swing.JLabel(); 
    jLabel4 = new javax.swing.JLabel(); 
    NameText = new javax.swing.JTextField(); 
    DateText = new javax.swing.JFormattedTextField(); 
    ProblemSolvingScoreText = new javax.swing.JTextField(); 
    ComprehensionScoreText = new javax.swing.JTextField(); 
    MemoryScoreText = new javax.swing.JTextField(); 
    AveragePercentageText = new javax.swing.JTextField(); 
    jButton1 = new javax.swing.JButton(); 
    jLabel5 = new javax.swing.JLabel(); 

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
    setResizable(false); 

    jLabel1.setText("Student Name"); 

    jLabel2.setText("Date of Quiz"); 

    jLabel3.setText("Score "); 

    jLabel4.setText("Average Percentage"); 

    DateText.setColumns(8); 
    try { 
     DateText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####"))); 
    } catch (java.text.ParseException ex) { 
     ex.printStackTrace(); 
    } 
    DateText.addKeyListener(new java.awt.event.KeyAdapter() { 
     public void keyTyped(java.awt.event.KeyEvent evt) { 
      DateTextKeyTyped(evt); 
     } 
    }); 

    ProblemSolvingScoreText.addKeyListener(new java.awt.event.KeyAdapter() { 
     public void keyTyped(java.awt.event.KeyEvent evt) { 
      ProblemSolvingScoreTextKeyTyped(evt); 
     } 
    }); 

    ComprehensionScoreText.addKeyListener(new java.awt.event.KeyAdapter() { 
     public void keyTyped(java.awt.event.KeyEvent evt) { 
      ComprehensionScoreTextKeyTyped(evt); 
     } 
    }); 

    MemoryScoreText.addKeyListener(new java.awt.event.KeyAdapter() { 
     public void keyTyped(java.awt.event.KeyEvent evt) { 
      MemoryScoreTextKeyTyped(evt); 
     } 
    }); 

    AveragePercentageText.setBackground(new java.awt.Color(240, 240, 240)); 

    jButton1.setText("Add Student"); 
    jButton1.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jButton1ActionPerformed(evt); 
     } 
    }); 

    jLabel5.setFont(new java.awt.Font("Rosewood Std Regular", 0, 36)); // NOI18N 
    jLabel5.setText("Add Student"); 

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
    getContentPane().setLayout(layout); 
    layout.setHorizontalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(layout.createSequentialGroup() 
      .addContainerGap() 
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 
       .addGroup(layout.createSequentialGroup() 
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 
         .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)) 
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE) 
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
         .addComponent(NameText, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(ComprehensionScoreText, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(MemoryScoreText, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(ProblemSolvingScoreText, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(DateText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) 
       .addGroup(layout.createSequentialGroup() 
        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 
         .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE) 
         .addComponent(AveragePercentageText)))) 
      .addGap(22, 22, 22)) 
     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
      .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addGap(74, 74, 74)) 
    ); 
    layout.setVerticalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(layout.createSequentialGroup() 
      .addGap(6, 6, 6) 
      .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
       .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addComponent(NameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
       .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addComponent(DateText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
       .addGroup(layout.createSequentialGroup() 
        .addGap(9, 9, 9) 
        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) 
       .addGroup(layout.createSequentialGroup() 
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
        .addComponent(ProblemSolvingScoreText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
      .addComponent(ComprehensionScoreText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) 
      .addComponent(MemoryScoreText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addGap(18, 18, 18) 
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
       .addComponent(AveragePercentageText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
      .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addGap(8, 8, 8)) 
    ); 

    pack(); 
}// </editor-fold>       

private void ProblemSolvingScoreTextKeyTyped(java.awt.event.KeyEvent evt) {             
    char c= evt.getKeyChar(); 
    if(!(Character.isDigit(c)|| (c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE))) 
    { 
     Toolkit tk = Toolkit.getDefaultToolkit(); 
     tk.beep(); 
     evt.consume(); 
    } 
}             

private void ComprehensionScoreTextKeyTyped(java.awt.event.KeyEvent evt) {             
    char c= evt.getKeyChar(); 
    if(!(Character.isDigit(c)|| (c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE))) 
    { 
     Toolkit tk = Toolkit.getDefaultToolkit(); 
     tk.beep(); 
     evt.consume(); 
    } 
}            

private void MemoryScoreTextKeyTyped(java.awt.event.KeyEvent evt) {           
    char c= evt.getKeyChar(); 
    if(!(Character.isDigit(c)|| (c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE))) 
    { 
     Toolkit tk = Toolkit.getDefaultToolkit(); 
     tk.beep(); 
     evt.consume(); 
    } 
}           

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {           

    try 
    { 
     String url = "jdbc:mysql://localhost:3306/StudentScores"; 
     String username = "admin3"; 
     String password = "admin3"; 

     Connection con = DriverManager.getConnection(url, username, password); 
     Statement stmt = con.createStatement(); 
     String Query = "INSERT INTO STUDENT (NAME, DATEOFQUIZ, MEMORYSCORE, COMPREHENSIONSCORE, PROBLEMSOLVINGSCORE, AVERAGEPERCENTAGE) VALUES ('"+NameText.getText()+"','"+DateText.getValue()+"','"+MemoryScoreText.getText()+"','"+ComprehensionScoreText.getText()+"','"+ProblemSolvingScoreText.getText()+"', '"+AveragePercentageText.getText()+"')"; 

     stmt.execute(Query); 

     JOptionPane.showMessageDialog(null, "Student Added"); 

     NameText.setText(null); 
     DateText.setText("00/00/0000"); 
     MemoryScoreText.setText(null); 
     ComprehensionScoreText.setText(null); 
     ProblemSolvingScoreText.setText(null); 
     AveragePercentageText.setText(null); 

    } 
    catch(SQLException ex) 
    { 
     JOptionPane.showMessageDialog(null, ex.toString()); 
    } 
}           

private void DateTextKeyTyped(java.awt.event.KeyEvent evt) {         
    char c= evt.getKeyChar(); 
    if(!(Character.isDigit(c)|| (c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE))) 
    { 
     Toolkit tk = Toolkit.getDefaultToolkit(); 
     tk.beep(); 
     evt.consume(); 
    }  

}         

public static void main(String args[]) { 
    java.awt.EventQueue.invokeLater(new Runnable() { 
     public void run() { 
      new AddStudent().setVisible(true); 
     } 
    }); 
} 

// Variables declaration - do not modify      
private javax.swing.JTextField AveragePercentageText; 
private javax.swing.JTextField ComprehensionScoreText; 
private javax.swing.JFormattedTextField DateText; 
private javax.swing.JTextField MemoryScoreText; 
private javax.swing.JTextField NameText; 
private javax.swing.JTextField ProblemSolvingScoreText; 
private javax.swing.JButton jButton1; 
private javax.swing.JLabel jLabel1; 
private javax.swing.JLabel jLabel2; 
private javax.swing.JLabel jLabel3; 
private javax.swing.JLabel jLabel4; 
private javax.swing.JLabel jLabel5; 
// End of variables declaration     

}

的地方閱讀,有人用過這個東西叫做「sed的」改變自己綁定地址和工作ed - 關於如何在Netbeans IDE上做到這一點的任何提示? (我是一個新手,所以請使用簡單的條款)

+2

發佈堆棧跟蹤時,發佈_complete_跟蹤(整個事情,即使它很長),並將其格式化爲代碼(縮進4個空格)。此外,請確定您的代碼中拋出異常的行。 –

+0

另外,由於這可能是一個MySQL配置問題,請向我們展示MySQL配置。 –

+0

@JimGarrison複製並粘貼了一切 – z33

回答

-1

您的MySQL服務器無法正常運行!

先啓動你的MySQL服務器,然後啓動你的應用程序!!!!!

+0

我不知道該怎麼做......我在運行之前連接到了數據庫 – z33

+0

您正在使用哪個版本的mysql –