链接mysql和netbeans数据时出错

时间:2015-11-08 12:13:40

标签: java mysql netbeans

我正在为我的学校项目使用mysql和Netbeans java。每当我尝试将详细信息注册到sql时,我都会收到此错误My SqlSyntaxErrorException:Unknown Column " [the data in the text field] in 'field list'" 这是我的代码:

  int age = Integer.parseInt(AgeTF.getText());
  String name=NameTF.getText();
  String id=IDTF.getText();
  String dob=DobTF.getText();
  String address=AddressTF.getText();

    try {           
        Class.forName("java.sql.Driver");
        String database = "jdbc:mysql://localhost:3306/final";
        Connection conn = DriverManager.getConnection(database, "root", "sanchit");
        Statement stmt = conn.createStatement();
        String sql = "insert into aadhar values ( '" + id + "', " + name + ", '" + dob + "' ,  '" + age + "'  , '" + address + "' );" ;
        stmt.executeUpdate(sql);
        }
    catch( Exception e){
         JOptionPane.showMessageDialog(null,"" + e);
    }
     JOptionPane.showMessageDialog(this,"You have been registered!");

请帮忙。 感谢

1 个答案:

答案 0 :(得分:0)

您没有用简单的引号保护名称

撰写if(date("H") < "17") echo "There are " . (16 - date("H")) . " hours and " . (60 - date("i")) . " minutes left until 17:00."; else if(date("H") == "17" && date("i") == "00") echo "It is 17:00."; else echo "17:00 is over for today."; 代替'" + name + "'

" + name + "