半结肠失踪的恐怖

时间:2015-06-09 13:12:36

标签: java netbeans-8

private void add_computer_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                                    
    // TODO add your handling code here:
    try{
    String url ="jdbc:derby://localhost:1527/Computer_Inventory";
    String usr ="admin1";
    String pass ="password";

    Connection con = DriverManager.getConnection(url,usr,pass); 

    Statement st = con.createStatement();
    String Query;
    Query = "INSERT INTO INVENTORY (EMP_NAME, DESIGNATION, ID, DEPARTMENT, COM_COMPANY, COM_MODEL, COM_SR_NO, COM_EXSER_TAG, PRIN_PRESENT, PRIN_COMPANY, PRIN_MODEL, PRIN_EXSER_TAG, PRIN_SR_NO, CARTRIDGE_MODEL, COMMISSION_DAY, COMMISSION_MONTH, COMMISSION_YEAR) VALUES ('"+emp_name_txt.getText()+"' , '"+designation_txt.getText()+"' , '"+emp_id_txt.getText()+"' , '"+emp_dept_txt.getText()+"' , '"+comp_company_txt.getText()+"' , '"+comp_model_txt.getText()+"' , '"+comp_serial_txt.getText()+"' , '"+comp_exsertag_txt.getText()+"' , '"+prin_present_combo.getSelectedItem()+"' , '"+prin_company_txt.getText()+"' , '"+prin_model_txt.getText()+"' , '"+prin_exsertag_txt.getText()+"' , '"prin_serial_txt.getText()"' , '"+prin_cartridge_txt.getText()+"' , '"+date_combo.getSelectedItem()+"' , '"+month_combo.getSelectedItem()+"' , '"+year_combo.getSelectedItem()+"')";

    JOptionPane.showMessageDialog(null, "Computer added to database");

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


    }
} 

它显示一个错误; mising(在“String Query = ...”中)。但我无法解决这个问题。 请帮忙。 我在netbeans中做这个。

非常感谢.. !!

1 个答案:

答案 0 :(得分:0)

如Sybren的评论所述,您应该使用参数进行查询。或者你也可以使用String.format()来使它看起来更好。

对于此问题,请搜索prin_serial_txt.getText()并在查询字符串中进行正确的连接。