Applet不会将结果保存到localhost

时间:2015-04-30 12:04:48

标签: java mysql database applet localhost

我尝试将Java Applet放在localhost上。在MySQL DB中保存结果的时候一切都还可以。当我在Netbeans中做的一切都很好,结果的保存工作完美。问题显示在localhost上执行代码时,结果不希望保存在数据库中。没有错误,也没有关于它的信息。

这是代码:

public void connection() {
        try{           
            String s1 = l10.getText();
            String s2 = l11.getText();
            String s3 = l12.getText();
            String s4 = l13.getText();
            String s5 = l14.getText();
            String s6 = l15.getText();

        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/draw", "root", "");

        Statement stmt = (Statement) con.createStatement();

        String insert = "INSERT INTO draw VALUES ('" + s1 + "', '" + s2 + "', '" + s3 + "', '" + s4 + "', '" + s5 + "', '" + s6 + "')";
        stmt.executeUpdate(insert);

        int msg2= JOptionPane.showConfirmDialog(null, 
                              "Saved", 
                              "Waring!", 
                              JOptionPane.YES_OPTION);
    }catch (Exception e) {
        int msg= JOptionPane.showConfirmDialog(null, 
                              "No connection with database\n" + e, 
                              "Warning!", 
                              JOptionPane.YES_OPTION);
    }
} 

1 个答案:

答案 0 :(得分:0)

INSERT中的draw查询您必须检查DataType与输入的匹配,并且必须在插入时编写字段名称

INSERT into draw ('') values('');