{"id":1108,"date":"2021-08-16T12:59:01","date_gmt":"2021-08-16T04:59:01","guid":{"rendered":"https:\/\/blog.odliken.top\/?p=1108"},"modified":"2025-03-18T16:46:58","modified_gmt":"2025-03-18T08:46:58","slug":"%e5%ad%a6%e7%94%9f%e4%bf%a1%e6%81%af%e7%ae%a1%e7%90%86%e7%b3%bb%e7%bb%9f%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/blog.odjbinail.cn\/?p=1108","title":{"rendered":"\u5b66\u751f\u4fe1\u606f\u7ba1\u7406\u7cfb\u7edf\u603b\u7ed3"},"content":{"rendered":"<h2>2021 \u5e74 7 \u6708 31 \u65e5\u65e9 8 \u70b9\u5de6\u53f3<\/h2>\n<p>1\u3001\u521b\u5efa\u597d\u6570\u636e\u5e93\u4e2d\u5bf9\u5e94\u8868\u7684\u5b9e\u4f53\u7c7b\uff08student\u3001teacher\u3001subject\u3001class_room\u3001sel_subject\uff09\u5982\uff1a<br \/>\n<img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/08\/image-20210801192341668.png\"  alt=\"\" \/><br \/>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/08\/image-20210801192341668.png\" alt=\"\" \/><br \/><\/noscript>\n2\u3001\u8fde\u63a5\u6570\u636e\u5e93<\/p>\n<ul>\n<li>IDEA\uff1a\u6587\u4ef6\u2014\u9879\u76ee\u7ed3\u6784\u2014\u5e93\u2014\u52a0\u53f7+\u2014java\u2014\u9009\u62e9\u5bf9\u5e94\u4e0b\u8f7d\u4f4d\u7f6e\u7684\u6587\u4ef6\u9a71\u52a8\u2014\u6dfb\u52a0\u2014\u4e00\u76f4 next<\/li>\n<\/ul>\n<p>3\u3001\u767b\u5f55\u754c\u9762<\/p>\n<ul>\n<li>\u901a\u8fc7\u8c03\u7528 stuDao\u3010\u8fde\u63a5\u6570\u636e\u5e93\u7684\u7c7b\u548c\u67e5\u8be2\u7528\u6237\u540d\u5bc6\u7801\u65b9\u6cd5\u3011\u7684\u65b9\u6cd5\u4ece\u6570\u636e\u5e93\u4e2d\u67e5\u8be2\u51fa\u7528\u6237\u4fe1\u606f\uff0c\u518d\u6bd4\u5bf9\u5bc6\u7801<\/li>\n<\/ul>\n<p>\uff081\uff09\u4e13\u95e8\u7528\u6237\u5bc6\u7801\u767b\u5f55<br \/>\n<img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/08\/image-20210801195229470.png\"  alt=\"\" \/><br \/>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/08\/image-20210801195229470.png\" alt=\"\" \/><br \/><\/noscript>\n\uff082\uff09\u4e0d\u540c\u7528\u6237\u540d\u548c\u5bc6\u7801\u767b\u5f55<\/p>\n<ul>\n<li>\n<p>\u767b\u5f55\u6210\u529f\u540e\u5f39\u51fa\uff0c\u53e6\u4e00\u4e2a\u754c\u9762\uff1a<\/p>\n<\/li>\n<li>\n<p>\u53ea\u9700\u5728\u767b\u5f55\u6210\u529f\u8bed\u53e5\u540e\uff0c\u52a0\u4e00\u4e2a\u65b0\u754c\u9762<\/p>\n<p>new MyFrame(&quot;\u5b66\u751f\u4fe1\u606f\u7ba1\u7406\u7cfb\u7edf&quot;,100,100,400,400);<\/p>\n<\/li>\n<li>\n<p><strong>\u5bc6\u7801\u4e0d\u53ef\u89c1\u6027\uff1a<\/strong>\u4f7f\u7528\u3010\u5bc6\u7801\u6846\u3011 JPasswordField t2;<\/p>\n<p>\u8f93\u5165\u7684\u662f\u4e00\u4e32\u7b26\u53f7<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">  @Override\npublic void actionPerformed(ActionEvent e) {\n    JButton b = (JButton)e.getSource();\n    if(b.equals(b2)){\n        this.setNull();\n    }else if(b.equals(b1)){\n        \/\/ \u901a\u8fc7\u8c03\u7528 stuDao \u7684\u65b9\u6cd5\u4ece\u6570\u636e\u5e93\u5145\u67e5\u8be2\u51fa\u7528\u6237\u4fe1\u606f\uff0c\u518d\u6bd4\u5bf9\u5bc6\u7801\n        StuDao stuDao = new StuDao();\n        Student student = stuDao.findByName(t1.getText());\n        if(student!=null&&student.getPassword().equals(t2.getText())){\n            JOptionPane.showMessageDialog(this, \"\u767b\u5f55\u6210\u529f\uff01\uff01\");\n            this.setVisible(false);\n            new MyFrame(\"\u5b66\u751f\u4fe1\u606f\u7ba1\u7406\u7cfb\u7edf\",100,100,400,400);\n        }else{             JOptionPane.showMessageDialog(this, \"\u7528\u6237\u540d\u6216\u5bc6\u7801\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01\");\n        }\n    }\n}<\/code><\/pre>\n<p>4\u3001\u7f16\u8f91\u4e3b\u754c\u9762<\/p>\n<\/li>\n<li>\n<p>\u91c7\u7528\u83dc\u5355\u9879\uff0c\u591a\u9762\u677f\u5207\u6362\u663e\u793a<\/p>\n<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">public class MyFrame extends JFrame implements ActionListener {\n    JMenuBar bar;\n    JMenu menu1\uff1b\n    JMenuItem add\uff1b\n    Panel contentPanel;\n public MyFrame(String title,int x,int y,int width,int height)\n    {\n        bar=new JMenuBar();\n\/\/1\u3001\u6dfb\u52a0\u8bb0\u5f55\u83dc\u5355\u9879\n        menu1=new JMenu(&quot;\u6dfb\u52a0\u8bb0\u5f55&quot;);\n        bar.add(menu1);\n        add=new JMenuItem(&quot;\u5b66\u751f&quot;);\n        menu1.add(add);\n        contentPanel=new Panel();\n        \/\/\u83dc\u5355\u9879\u6dfb\u52a0\u4e8b\u4ef6\u76d1\u542c\u5668\n        add.addActionListener(this);\n\/\/\u8bbe\u7f6e\u7a97\u53e3\u5c5e\u6027\n        this.setJMenuBar(bar);\n        this.setContentPane(new JLabel());\n        this.setTitle(title);\n        this.setBounds(x, y, width, height);\n        this.setVisible(true);          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n }\n}\n @Override\n    public void actionPerformed(ActionEvent e) {\n        Object obj=e.getSource();\n        if(obj==add){\n            changeContentPane(new AddPanel());\n        }else if(obj==delete1){\n            changeContentPane(new DeletePanel());\n        }\n    }\n\/\/\u5207\u6362\u5185\u5bb9\u9762\u677f\n    public void changeContentPane(Container contentPane){\n        this.setContentPane(contentPane);\n        this.revalidate();\n    }<\/code><\/pre>\n<ul>\n<li>\n<p>\u7136\u540e\u5206\u522b\u521b\u6bcf\u4e2a\u83dc\u5355\u9879\u7684\u9762\u677f\u7c7b\uff0c\u4e0d\u65ad\u8fd0\u884c\uff0c\u8c03\u6574\u6bcf\u4e2a\u6587\u672c\u6846\u7684\u4f4d\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u610f\u7ec6\u8282\uff1a\u6309\u94ae\u6dfb\u52a0\u76d1\u89c6\u5668<\/p>\n<p>\u200b                 \u5b9e\u4f8b\u5316\u6bcf\u4e2a\u5e73\u9762<\/p>\n<p>\u200b                 \u89d2\u6807\u6b63\u786e<\/p>\n<h2>2021 \u5e74 8 \u6708 1 \u65e5 10 \u70b9\u5de6\u53f3<\/h2>\n<\/li>\n<\/ul>\n<p>1\u3001\u62a5\u9519\uff1aLocal variable 'stu' is redundant<br \/>\n\u5c40\u90e8\u53d8\u91cf\u662f\u591a\u4f59\u7684<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">stu = new Student(number,name,sex,password,score);\n return stu;\n \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n return new Student(number,name,sex,password,score);\n ```\n 2\u3001\u6253\u5f00\u591a\u4e2a\u6a21\u677f\n\u200b       \u53f3\u4e0a\u89d2\u8bbe\u7f6e\u2014\u9879\u76ee\u7ed3\u6784\u2014\u52a0\u53f7\u2014\u65b0\u5efa\u3001\u5bfc\u5165\u2014\u786e\u5b9a\n3\u3001IDEA \u91cd\u542f\n\u200b       \u6587\u4ef6\u2014\u2014\u6e05\u9664\u7f13\u5b58\u2014\u2014\u91cd\u542f\n4\u3001IDEA \u9879\u76ee\u91cd\u6784\n\u200b       \u83dc\u5355\u680f\u4e0b\u9762\u7684\u6994\u5934\u5f62\u72b6\u7684\u7eff\u8272  \u6784\u5efa\u9879\u76ee\n5\u3001\u5728\u4e3b\u9762\u677f\u4e2d\u5f39\u51fa\u53e6\u4e00\u4e2a\u754c\u9762\n\u200b           \u5728\u591a\u9762\u677f\u4e2d\uff0c\u6dfb\u52a0\u4e00\u4e2a\u6309\u94ae\u3001\u7136\u540e\n\u200b           \u6d4f\u89c8\u2014\u2014\u70b9\u51fb\u6d4f\u89c8\u4fe1\u606f\u2014\u2014\u786e\u5b9a\n```java\n @Override\n    public void actionPerformed(ActionEvent e) {\n        JButton b = (JButton)e.getSource();\n        if(b.equals(b1)){            JOptionPane.showMessageDialog(this, \"\u8bf7\u5148\u6dfb\u52a0\u4f60\u9700\u8981\u6d4f\u89c8\u7684\u5185\u5bb9!!\");\/\/\u70b9\u51fb\u786e\u5b9a\n            new Sframe(\"\u6d4f\u89c8\",400,400,500,500);\n        }\n    }<\/code><\/pre>\n<h2>2021 \u5e74 8 \u6708 2 \u65e5\u5348 9 \u70b9\u591a<\/h2>\n<p>1\u3001\u663e\u5f0f\u7c7b\u578b\u53c2\u6570 Student \u53ef\u4ee5\u66ff\u6362\u4e3a &lt;&gt;<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">List<student> list;\n  list = new ArrayList<student>();\n \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n List<student> list;\n  list = new ArrayList<>();<\/code><\/pre>\n<p>2\u3001\u5220\u9664\u529f\u80fd<\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5\u8981\u5148\u5b9e\u4f8b\u51fa\u8be5\u65b9\u6cd5\u7684\u5bf9\u8c61<\/p>\n<p>dao=new StuDao();<\/p>\n<p>\u5426\u5219 \u4f1a\u62a5\u9519 \u5220\u9664\u5931\u8d25<br \/>\n<img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/08\/image-20210802113529224.png\"  alt=\"\" \/><br \/>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/08\/image-20210802113529224.png\" alt=\"\" \/><br \/><\/noscript>\n3\u3001Statement \u4e2d\u7684\u4e09\u4e2a executeXXX()\u65b9\u6cd5<\/p>\n<ul>\n<li>executeQuery: \u53ea\u80fd\u6267\u884c select \u8bed\u53e5<\/li>\n<li>executeUpdate: \u53ef\u4ee5\u6267\u884c insert\u3001delete \u548c update \u8bed\u53e5\uff0c\u4f46\u4e0d\u80fd\u6267\u884c select<\/li>\n<li>execute:\u589e\u5220\u6539\u67e5\u7684 4 \u79cd(\u4efb\u610f)\u8bed\u53e5\u90fd\u80fd\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>4\u3001\u6309\u59d3\u540d\u5220\u9664\u529f\u80fd<\/p>\n<ul>\n<li>\u6309\u4ec0\u4e48\u5220\u9664 \u5219  where xxx=\uff1f<\/li>\n<li>\u5728\u7a97\u53e3\u4e00\u4e2a\u754c\u9762\u4e2d\u6309\u5b66\u53f7(\u59d3\u540d)\u5220\u9664\u7684\u6309\u94ae\uff0c\u5206\u5f00\u5b9a\u4e49\u5404\u65b9\u6cd5(\u5373\u4f7f\u4e00\u6837\u7684\u65b9\u6cd5\uff0c\u6539\u4e2a\u540d\u5b57)<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">\/\/\u6309\u59d3\u540d\u5220\u9664\npublic boolean delete2(String name)\n    {\n        boolean flag = false;\n        con = getCon();\n        try {\n            pst = con.prepareStatement(\"delete from student where name=?\");\n            pst.setString(1, name);\/\/\u6309\u4ec0\u4e48\u5219\u5b9a\u4e49\u4ec0\u4e48\n            pst.execute();\n            flag = true;\n            pst.close();\n            con.close();\n        } catch (SQLException e) {\n            e.printStackTrace();\n        }\n        return flag;\n    }\n@Override\npublic void actionPerformed(ActionEvent e) {\nif(b==b3){\n            dao=new StuDao();\n            String name = t2.getText();\n            if(dao.delete2(name)) {\n                JOptionPane.showMessageDialog(this, \"\u606d\u559c\u4f60\u5220\u9664\u6210\u529f\uff01\uff01\");\n            }else{\n                JOptionPane.showMessageDialog(this, \"\u5220\u9664\u5931\u8d25\uff01\uff01\uff01\");\n            }\n            this.setNull1();\n        }\n    }<\/code><\/pre>\n<p>5\u3001\u6dfb\u52a0\u529f\u80fd<\/p>\n<ul>\n<li>\n<p>\u62a5\u9519\uff1aColumn count doesn&#039;t match value count at row 1 <\/p>\n<p>\u200b    \u5217\u4e0d\u5339\u914d<\/p>\n<p><strong><em>\u8981\u5148\u770b\u62a5\u9519\uff0c\u800c\u4e0d\u662f\u5728\u9519\u7684\u90a3\u4e00\u884c\uff0c\u81ea\u5df1\u76f2\u76ee\u6539\u9519<\/em><\/strong><\/p>\n<\/li>\n<li>\n<p>\u62a5\u9519\uff1aCan not issue data manipulation statements with executeQuery()<\/p>\n<p>\u4e0d\u80fd\u53d1\u51fa\u6570\u636e\u64cd\u7eb5\u8bed\u53e5\u4e0e executeQuery() <\/p>\n<ul>\n<li>executeQuery: \u53ea\u80fd\u6267\u884c select \u8bed\u53e5<\/li>\n<li>executeUpdate: \u53ef\u4ee5\u6267\u884c insert\u3001delete \u548c update \u8bed\u53e5\uff0c\u4f46\u4e0d\u80fd\u6267\u884c select<\/li>\n<li>execute:\u589e\u5220\u6539\u67e5\u7684 4 \u79cd(\u4efb\u610f)\u8bed\u53e5\u90fd\u80fd\u6267\u884c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6dfb\u52a0\u90e8\u5206\u6570\u636e<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">\/\/3\u3001\u521b\u5efa\u9884\u5904\u7406\u8bed\u53e5\u5bf9\u8c61\npst = con.prepareStatement(\"insert into student values(null,?,?,?,?,null)\");\n\/\/\u6ca1\u6709\u6dfb\u52a0\u7684\u6570\u636e\u7528 null \u8868\u793a\n        pst.setInt(1, number);\n        pst.setString(2, name);\n        pst.setInt(3, sex);\n        pst.setDouble(4, score);\n\/\/\u8fd9\u4e9b 1\u30012\u30013\u30014 \u5bf9\u5e94\u7684\u662f\uff1f\u5728\u7b2c\u51e0\u4e2a\u7684\u4f4d\u7f6e<\/code><\/pre>\n<p>6\u3001statement \u548c prepareStatement \u7684\u533a\u522b<\/p>\n<\/li>\n<li>\n<p>JDBC \u9a71\u52a8\u4f1a\u53d1\u9001\u4e00\u4e2a\u7f51\u7edc\u8bf7\u6c42\u5230\u6570\u636e\u89e3\u6790\u548c\u4f18\u5316\u8fd9\u4e2a\u67e5\u8be2\uff0c\u800c\u6267\u884c\u65f6\u4f1a\u4ea7\u751f\u53e6\u4e00\u4e2a\u7f51\u7edc\u8bf7\u6c42\uff0c\u5728 JDBC \u9a71\u52a8\u4e2d\uff0c\u51cf\u5c11\u7f51\u7edc\u901a\u8baf\u662f\u6700\u7ec8\u7684\u76ee\u7684. <\/p>\n<\/li>\n<li>\n<p>\u8bbf\u95ee\u6570\u636e\u5e93\u7684\u901f\u5ea6\uff1a<\/p>\n<p>prepareStatement \u4f1a\u5148\u521d\u59cb\u5316 SQL\uff0c\u5148\u628a\u8fd9\u4e2a SQL \u63d0\u4ea4\u5230\u6570\u636e\u5e93\u4e2d\u8fdb\u884c\u9884\u5904\u7406\uff0c\u591a\u6b21\u4f7f\u7528\u53ef\u63d0\u9ad8\u6548\u7387\u3002<br \/>\ncreateStatement \u4e0d\u4f1a\u521d\u59cb\u5316\uff0c\u6ca1\u6709\u9884\u5904\u7406\uff0c\u6bcf\u6b21\u90fd\u662f\u4ece 0 \u5f00\u59cb\u6267\u884c<\/p>\n<\/li>\n<li>\n<p>SQL \u5bf9\u4e8e\u53ea\u6267\u884c\u4e00\u6b21\u7684 SQL \u8bed\u53e5\u9009\u62e9 Statement \u662f\u6700\u597d\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u76f8\u53cd, \u5982\u679c SQL \u8bed\u53e5\u88ab\u591a\u6b21\u6267\u884c\u9009\u7528 PreparedStatement \u662f\u6700\u597d\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>PreparedStatement \u7684\u7b2c\u4e00\u6b21\u6267\u884c\u6d88\u8017\u662f\u5f88\u9ad8\u7684\uff0c \u5b83\u7684\u6027\u80fd\u4f53\u73b0\u5728\u540e\u9762\u7684\u91cd\u590d\u6267\u884c\uff0c\u4f7f\u7528 PreparedStatement \u7684\u65b9\u5f0f\u6765\u6267\u884c\u4e00\u4e2a\u9488\u5bf9\u6570\u636e\u5e93\u8868\u7684\u67e5\u8be2\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u7a0b\u5e8f\u5728\u8fd0\u884c\u671f\u95f4\u53ea\u9700\u8981\u4e00\u6b21\u8bf7\u6c42, \u90a3\u4e48\u5c31\u4f7f\u7528 Statement. \u5bf9\u4e8e Statement, \u540c\u4e00\u4e2a\u67e5\u8be2\u53ea\u4f1a\u4ea7\u751f\u4e00\u6b21\u7f51\u7edc\u5230\u6570\u636e\u5e93\u7684\u901a\u8baf.<\/p>\n<\/li>\n<\/ul>\n<p>7\u3001\u6309\u5b66\u53f7\u67e5\u8be2<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\"> public Student findById(int id)\n    {\n        Student stu = null;\n        con = getCon();\n        try {\n            pst = con.prepareStatement(\"select * from student where number=?\");\n            pst.setInt(1, id);\n            rs= pst.executeQuery();\n            if(rs.next())\n            {\/\/2\u30013\u30014\u30015 \u662f\u6570\u636e\u5e93\u4e2d\u5217\u7684\u4f4d\u7f6e\n                int number = rs.getInt(2);\n                String name = rs.getString(3);\n                int  sex = rs.getInt(4);\n                int score=rs.getInt(5);\n                stu = new Student(number,name,sex,score);\n            }\n        }catch (SQLException e) {\n            e.printStackTrace();\n        }\n        return stu;\n    }<\/code><\/pre>\n<p>8\u3001\u66f4\u65b0\u529f\u80fd<\/p>\n<ul>\n<li>\n<p>\u5148\u6dfb\u52a0\u4e00\u4e2a\u67e5\u627e\u6309\u94ae\u5728\u66f4\u65b0\u754c\u9762\u91cc\u9762\u3001\u67e5\u627e\u51fa\u6765\u4e4b\u540e\u518d\u4fee\u6539\u6570\u636e\u70b9\u51fb\u66f4\u65b0<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">pst = con.prepareStatement(\"update student set name=?,sex=?,score=? number=?\");\n        pst.setString(1, stu.getName());\n        pst.setInt(2, stu.getSex());\n        pst.setInt(3,stu.getScore());\n        pst.setInt(4, stu.getNumber());\n\/\/\u5982\u679c\u6ca1\u6709 where number=? \u8bed\u53e5\u5219\u6570\u636e\u5e93\u4e2d\u6570\u636e\u5168\u6539\u4e3a\uff0c\u754c\u9762\u4e0a\u7684\u6570\u636e\u4e86\n\/\/\u6b63\u786e\u7684\uff1a\npublic boolean update(Student stu)\n{\n    boolean flag = false;\n    con = getCon();\n    try {\n        \/\/\u6ce8\u610f\u95ee\u53f7\u548c 1\/2\/3\/4  \u6570\u636e\u8981\u5bf9\u5e94\u3001\u5426\u5219\u4f1a\u6df7\u4e71\u6570\u636e\n        pst = con.prepareStatement(\"update student set name=?,sex=?,score=? where number=?\");\n        pst.setString(1, stu.getName());\n        pst.setInt(2, stu.getSex());\n        pst.setInt(3,stu.getScore());\n        pst.setInt(4, stu.getNumber());\n        pst.executeUpdate();\n        flag = true;\n    } catch (SQLException e) {\n        e.printStackTrace();\n    }\n    return flag;\n}<\/code><\/pre>\n<p>9\u3001\u9009\u8bfe\u529f\u80fd<\/p>\n<\/li>\n<li>\n<p>\u5b9a\u4e49\u4e00\u4e2a\u6dfb\u52a0\u5230\u6570\u636e\u5e93 student \u8868\u4e2d\u8bfe\u7a0b\u7684\u9009\u62e9\u6309\u94ae\uff08\u5b57\u4e3a\u9009\u62e9\uff0c\u5b9e\u5219\u8d4b\u4e88\u6dfb\u52a0\u529f\u80fd\uff09\uff0c\u548c\u4e00\u4e2a\u9009\u8bfe\u5b8c\u4e4b\u540e\u7684\u67e5\u8be2\u663e\u793a\u529f\u80fd<\/p>\n<\/li>\n<li>\n<p>\u62a5\u9519\uff1aColumn &#039;id&#039; cannot be null<\/p>\n<p>\u4e3b\u952e id \u8981\u8bbe\u7f6e\u4e3a\u81ea\u52a8\u9012\u589e\u3010Default\u2014\u2014AUTO_INCREMENT\u3011\u5426\u5219\u6dfb\u52a0\u4e0d\u8fdb\u53bb<\/p>\n<\/li>\n<li>\n<p>\u8d4b\u4e88\u6309\u94ae\u529f\u80fd\u65f6\uff0c\u8981\u6ce8\u610f\u6309\u94ae\u89d2\u6807\u6b63\u786e\u3002<\/p>\n<\/li>\n<\/ul>\n<p>10\u3001\u767b\u5f55\u7684\u4e09\u4e2a\u7ec4\u4ef6<\/p>\n<ul>\n<li>JTextField\u3010\u6587\u672c\u6846\u3011\uff1a\u7528\u4e8e\u8f93\u51fa\u6587\u672c\u3001\u662f\u660e\u6587\u3002<\/li>\n<li>JPasswordField \u3010\u5bc6\u7801\u6846\u3011\uff1a\u7528\u4e8e\u8f93\u5165\u5bc6\u7801\uff0c\u8f93\u5165\u7684\u662f\u4e00\u4e32\u7b26\u53f7<\/li>\n<li>JLabel\uff1a\u7528\u4e8e\u663e\u793a\u4e00\u4e32\u5b57\u7b26\u3002\uff08\u6587\u672c\u6846\u548c\u5bc6\u7801\u6846\u7684\u5b57\u5c31\u662f\u6807\u7b7e\uff09<\/li>\n<\/ul>\n<p>10\u3001\u6ce8\u518c\u754c\u9762<\/p>\n<ul>\n<li><strong>\u589e\u52a0\u6ce8\u518c\u529f\u80fd\uff1a<\/strong>\u6dfb\u52a0\u529f\u80fd\uff1a\u6dfb\u52a0\u7528\u6237\u540d\u548c\u5bc6\u7801\u5230\u6570\u636e\u5e93\u4e2d<\/li>\n<li>\u5728\u6ce8\u518c\u754c\u9762\u65f6\uff1a\u5220\u53bb\u6b64\u884c\u4ee3\u7801\uff0c\u7136\u540e\u6ce8\u518c\u5b8c\u4e4b\u540e\uff0c\u70b9\u51fb\u53f3\u4e0a\u89d2\u53c9\u53c9\u00d7\uff0c\u8fd4\u56de\u5f00\u59cb\u754c\u9762\uff0c\u8fdb\u884c\u767b\u5f55\u3002<\/li>\n<li>this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<\/li>\n<li>\u200b        this.setUndecorated(true);  \u3010\u8bbe\u7f6e\u7a97\u53e3\u4e0d\u53ef\u79fb\u52a8\uff0c\u65e0\u9876\u90e8\u6807\u9898\u7b49\u88c5\u9970\u3011<\/li>\n<li>this.setLocationRelativeTo(null); \u3010\u5c4f\u5e55\u6b63\u4e2d\u592e\u3011<br \/>\n<img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/08\/image-20210804145331150.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/08\/image-20210804145331150.png\" alt=\"\" \/><\/p><\/noscript>\n<h2>8 \u6708 4 \u65e5\u5348 11 \u70b9\u5de6\u53f3<\/h2>\n<\/li>\n<\/ul>\n<p>1\u3001\u53d8\u91cf\u547d\u540d\u89c4\u8303<\/p>\n<p>\u9996\u5355\u8bcd\u5b57\u6bcd\u5c0f\u5199\uff0c\u540e\u9762\u6bcf\u4e00\u4e2a\u5355\u8bcd\u9996\u5b57\u6bcd\u5927\u5c0f\u3001\u9a7c\u5cf0\u539f\u5219\uff0c\u77e5\u6653\u5176\u610f<\/p>\n<p>2\u3001 \u6539\u4e3a\u6570\u636e\u8868\u754c\u9762<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">public class MyTableByTeacher extends JFrame implements ActionListener {\n    JTable jTable;\n     public MyTableByTeacher() throws SQLException, ClassNotFoundException {\n        StuDao stuDao = new StuDao();\n        String arr[] = {\"\u5b66\u53f7\", \"\u540d\u5b57\", \"\u6027\u522b\", \"\u6210\u7ee9\", \"\u4e13\u4e1a\"};\n        String comm[][] = stuDao.getStudentList();\n         \/\/\u4ee5 comm \u548c arr \u4e3a\u53c2\u6570\uff0c\u521b\u5efa\u4e00\u4e2a\u8868\u683c\n        dtm = new DefaultTableModel(comm, arr);\n        jTable = new JTable(dtm);\n         \/\/\u8bbe\u7f6e\u6b64\u8868\u89c6\u56fe\u7684\u9996\u9009\u5927\u5c0f\n        jTable.setPreferredScrollableViewportSize(new Dimension(600, 150));\n        \/\/\u5c06\u8868\u683c\u52a0\u5165\u5230\u6eda\u52a8\u6761\u7ec4\u4ef6\u4e2d\n        scrollPane = new JScrollPane(jTable);\n        this.add(scrollPane, BorderLayout.CENTER);\n       jTable.getTableHeader().setReorderingAllowed(false);\/\/\u5217\u4e0d\u80fd\u79fb\u52a8\n        jTable.getTableHeader().setResizingAllowed(false);\/\/\u4e0d\u53ef\u62c9\u52a8\u8868\u683c\n\/\/      jTable.setEnabled(false);\/\/\u8868\u683c\u4e0d\u53ef\u66f4\u6539\u6570\u636e\n          this.setTitle(\"\u6570\u636e\u8868\");\n        this.setVisible(true);\/\/\u8bbe\u7f6e\u7a97\u4f53\u53ef\u89c1\n        this.validate();\/\/\u8bbe\u7f6e\u7ec4\u4ef6\u53ef\u89c1\n        this.pack();\/\/\u81ea\u52a8\u8c03\u6574\u7ec4\u5efa\u5927\u5c0f\u4f7f\u6bcf\u4e2a\u7ec4\u4ef6\u90fd\u80fd\u663e\u793a\n        this.setBounds(200, 200, 600, 260);\n        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n     }<\/code><\/pre>\n<p>3\u3001\u52a8\u6001\u5237\u65b0\u529f\u80fd<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">  StuDao \u7c7b\u4e2d\uff1a\n\/\/\u5237\u65b0\n    public void changTable(DefaultTableModel dtm) {\n        String[][] comm = getGoodsList(\"\", \"\");\n        int index = dtm.getRowCount();\n        while (index != 1) {\n            try {\n                dtm.removeRow(0);\n                index = dtm.getRowCount();\n            } catch (RuntimeException e) {\n                e.printStackTrace();\n            }\n        }\n        for (int i = 0; i < comm.length; i++) {\n            dtm.addRow(comm[i]);\n        }\n        dtm.removeRow(0);\n        dtm.fireTableDataChanged();\n    }\n    public String[][] getStudentList(){\n        con = getCon();\n        try {\n            pst = con.prepareStatement(\"select * from student \");\n            rs = pst.executeQuery();\n            rs.last();int row = rs.getRow();\/\/\u83b7\u53d6\u8bb0\u5f55\u7684\u603b\u6761\u6570\n            rs.beforeFirst();\/\/\u6e38\u6807\u56de\u5230\u7b2c\u4e00\u4e2a\u8bb0\u5f55\u524d\u7684\u4f4d\u7f6e\n            String comm[][] = new String[row][5];\/\/row \u884c\u30015 \u5217\n            rs.next();\/\/\u6e38\u6807\u56de\u5230\u7b2c\u4e00\u4e2a\u8bb0\u5f55\u7684\u4f4d\u7f6e\n            for (int i = 0; i < row; i++) {\n                comm[i][0] = rs.getString(\"number\");\n                comm[i][1] = rs.getString(\"name\");\n                comm[i][2] = rs.getString(\"sex\");\n                comm[i][3] = rs.getString(\"score\");\n                comm[i][4] = rs.getString(\"profession\");\n                rs.next();\n            }\n            rs.close();\n            return comm;\n        } catch (SQLException e) {\n            e.printStackTrace();\n            try {\n                pst.close();\n                con.close();\n            } catch (SQLException throwables) {\n                throwables.printStackTrace();\n            }\n        }\n        return null;\n    }<\/code><\/pre>\n<p>4\u3001\u9500\u6bc1\u7a97\u53e3<br \/>\ndispose();<\/p>\n<p>5\u3001\u8001\u5e08\u8eab\u4efd\u7684\u6570\u636e\u8868\u65b0\u589e\u529f\u80fd\uff1a<\/p>\n<p><strong>\u6570\u636e\u5b66\u53f7\u552f\u4e00\u6027?\/?\/\u3010\u8be5\u5b66\u53f7\u5df2\u7ecf\u5b58\u5728\uff0c\u5f39\u51fa\u5bf9\u8bdd\u6846\uff0c\u5224\u65ad\u65b0\u589e\u5b66\u53f7\u662f\u5426\u5b58\u5728\u4e8b\u4ef6\uff1f\uff1f\uff1f\u3011\uff08&quot;\u56e0\u4e3a\u6211\u5728\u7b2c\u4e00\u4e2a\u6587\u672c\u6846\u53f3\u8fb9\u52a0\u5165\u4e86\u4e00\u4e2a\u6807\u7b7e\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u7f16\u53f7\u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u5c31\u4f1a\u51fa\u73b0\u4e00\u4e2a\u7ea2\u00d7\u4e0d\u53ef\u4ee5\u6ce8\u518c\uff0c\u7eff\u8272\u221a\u4ee3\u8868\u53ef\u4ee5\u6ce8\u518c.&quot;\uff1f\uff1f)<\/strong><\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">JButton b = (JButton)e.getSource();\n\/\/ \u6dfb\u52a0\nif (b== keep) {\n    dao=new StuDao();\n    Student stu=this.getStu();\n    if (dao.addStudent(stu)) {\n        JOptionPane.showMessageDialog(this, \"\u606d\u559c\u4f60\u6dfb\u52a0\u6210\u529f\uff01\uff01\");\n        StuDao stuDao = new StuDao();\n        stuDao.changTable(dtm);\n        \/\/ \u9500\u6bc1\u7a97\u53e3\u3001\u5c31\u53ef\u4ee5\u9500\u6bc1\u4e0a\u4e00\u4e2a\u7a97\u53e3\n                dispose();\n }<\/code><\/pre>\n<p>6\u3001\u8001\u5e08\u8eab\u4efd\u7684\u6570\u636e\u8868\u4fee\u6539\u529f\u80fd<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">public class MyTableByTeacher extends JFrame implements ActionListener {\n    JTable jTable;\n     public MyTableByTeacher() throws SQLException, ClassNotFoundException {\n\/\/ \u76d1\u542c\u8868\u683c\u4e2d\u4fee\u6539\u53d8\u5316\n        jTable.getModel().addTableModelListener(new TableModelListener() {\n            @Override\n            public void tableChanged(TableModelEvent e) {\n                \/\/ \u83b7\u53d6\u5230\u4fee\u6539\u7684\u7b2c\u51e0\u5217\n                int col = e.getColumn();\n                \/\/\u83b7\u53d6\u5230\u4fee\u6539\u7684\u7b2c\u51e0\u884c\n                int row = e.getFirstRow();\n                Student stu = new Student();\n                String number = (String) dtm.getValueAt(row, 0);\n                stu.setNumber(Integer.parseInt(number));\n                String name = (String) dtm.getValueAt(row, 1);\n                stu.setName(name);\n                String sex = (String) dtm.getValueAt(row, 2);\n                stu.setSex(Integer.parseInt(sex));\n                String score = (String) dtm.getValueAt(row, 3);\n                stu.setScore(Integer.parseInt(score));\n                String profession = (String) dtm.getValueAt(row, 4);\n                stu.setProfession(profession);\n                stuDao.update(stu);\n            }\n        });\n     }\n \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n     @Override\n    public void actionPerformed(ActionEvent e) {\n        JButton b = (JButton) e.getSource();\n        if (b == update) {\n            UpdateFrame updateFrame = new UpdateFrame(\"\u66f4\u65b0\", 500, 500, 320, 260);\n            updateFrame.setDtm(dtm);\n            int row = jTable.getSelectedRow();\n            if (row != -1) {\n                String number = (String) dtm.getValueAt(row, 0);\n                updateFrame.number.setText(number);\n                updateFrame.name.setText((String) dtm.getValueAt(row, 1));\n                updateFrame.sex.setText((String) dtm.getValueAt(row, 2));\n                updateFrame.score.setText((String) dtm.getValueAt(row, 3));\n                updateFrame.profession.setText((String) dtm.getValueAt(row, 4));\n            }\n        }\n    }<\/code><\/pre>\n<p>7\u3001\u8001\u5e08\u8eab\u4efd\u7684\u6570\u636e\u8868\u5220\u9664\u529f\u80fd<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">if (b == delete) {\n            int row = jTable.getSelectedRow();\n            if (row != -1) {\n                String number = (String) dtm.getValueAt(row, 0);\n                StuDao stuDao = new StuDao();                           stuDao.deleteByNumber(Integer.parseInt(number));\n                stuDao.changTable(dtm);\n                System.out.println(number);\n            }\n        }<\/code><\/pre>\n<p>8\u3001 \u5b66\u751f\u8eab\u4efd\u9009\u8bfe\u4e0b\u62c9\u5217\u8868<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-java\">public class underChoose extends Panel implements ActionListener{\n    JLabel chooseSubject;\n    JComboBox underSubject;\n    JButton choose;\n    JPanel p1;\n    public underChoose(){\n        chooseSubject =new JLabel(\"\u9009\u62e9\u8bfe\u7a0b\");\n        underSubject =new JComboBox();\n        underSubject.addActionListener(this);\n        choose =new JButton(\"\u9009\u62e9\");\n        choose.addActionListener(this);\n        String List1[]={\"\u8ba1\u7b97\u673a\",\"\u97f3\u4e50\",\"\u7f8e\u672f\"};\n        for (int i = 0; i < 3; i++) {\n            underSubject.addItem(List1[i]);\n        }\n        p1 =new JPanel();\n        p1.add(chooseSubject);\n        p1.add(underSubject);\n        this.add(p1,BorderLayout.CENTER);\n        this.setLayout(new FlowLayout());\n        this.setVisible(true);\n    }\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n    public SelSubject getSel() {\n        SelSubject sel=new SelSubject();       underSubject.getSelectedItem());\n        return sel;\n    }\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n@Override\n public void actionPerformed(ActionEvent e) {\n      if(underSubject.getSelectedItem()==\"\u8ba1\u7b97\u673a\"&&e.getSource()== choose||underSubject.getSelectedItem()==\"\u97f3\u4e50\"&&e.getSource()== choose||underSubject.getSelectedItem()==\"\u7f8e\u672f\"&&e.getSource()== choose){\n          dao = new SelSubDao();\n            SelSubject sel = this.getSel();\n            if(dao.addSelSubject(sel)){                JOptionPane.showMessageDialog(this, \"\u9009\u62e9\u6210\u529f\uff01\uff01\");\n            }else{               JOptionPane.showMessageDialog(this, \"\u8f93\u5165\u683c\u5f0f\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01\");}\n      }\n }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2021 \u5e74 7 \u6708 31 \u65e5\u65e9 8 \u70b9\u5de6\u53f3 1\u3001\u521b\u5efa\u597d\u6570\u636e\u5e93\u4e2d\u5bf9\u5e94\u8868\u7684\u5b9e\u4f53\u7c7b\uff08student\u3001teacher [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1108","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/1108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1108"}],"version-history":[{"count":1,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/1108\/revisions"}],"predecessor-version":[{"id":4979,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/1108\/revisions\/4979"}],"wp:attachment":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}