用eclipse作为开发系统的前端,对数据库进行增加数据的功能,但是Java程序运行之后无法更新数据库
求大神帮我修改!麻烦在修改的时候说明原因publicclassStudentAddextendsJPanelimplementsActionListener{Connec...
求大神帮我修改!麻烦在修改的时候说明原因public class StudentAdd extends JPanel implements ActionListener{ Connection con; Statement sql; JButton b1,b2; JTextField tf1,tf2,tf3,tf4,tf5,tf6; Box baseBox,bv1,bv2; StudentAdd(){ try{ Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){} try{ con=DriverManager.getConnection("jdbc:mysqls://localhost:3306/test","root","123456"); sql=con.createStatement(); } catch(SQLException e){} setLayout(new BorderLayout()); JPanel p1=new JPanel(); JPanel p2=new JPanel(); tf1=new JTextField(16); tf2=new JTextField(16); tf3=new JTextField(16); tf4=new JTextField(16); tf5=new JTextField(16); tf6=new JTextField(16); b1=new JButton("录入"); b2=new JButton("重置"); b1.addActionListener(this); b2.addActionListener(this); p1.add(b1); p1.add(b2); bv1=Box.createVerticalBox(); bv1.add(new JLabel("学号")); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel("姓名")); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel("性别")); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel("专业")); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel("地址")); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel("电话")); bv1.add(Box.createVerticalStrut(8)); bv2=Box.createVerticalBox(); bv2.add(tf1); bv2.add(Box.createVerticalStrut(8)); bv2.add(tf2); bv2.add(Box.createVerticalStrut(8)); bv2.add(tf3); bv2.add(Box.createVerticalStrut(8)); bv2.add(tf4); bv2.add(Box.createVerticalStrut(8)); bv2.add(tf5); bv2.add(Box.createVerticalStrut(8)); bv2.add(tf6); bv2.add(Box.createVerticalStrut(8)); baseBox=Box.createHorizontalBox(); baseBox.add(bv1); baseBox.add(Box.createHorizontalStrut(10)); baseBox.add(bv2); p2.add(baseBox); add(p1,"South"); add(p2,"Center"); setSize(400,300); setBackground(Color.pink); }public void actionPerformed(ActionEvent e){ if(e.getSource()==b1){ try{insert();} catch(SQLException ee){} JOptionPane.showMessageDialog(this,"数据已入库!","提示",JOptionPane.INFORMATION_MESSAGE); }else if(e.getSource()==b2){ tf1.setText(""); tf2.setText(""); tf3.setText(""); tf4.setText(""); tf5.setText(""); tf6.setText(""); }}private void insert() throws SQLException { String 学号=","+tf1.getText().trim()+","; String 姓名=","+tf2.getText().trim()+","; String 性别=","+tf3.getText().trim()+","; String 专业=","+tf4.getText().trim()+","; String 地址=","+tf5.getText().trim()+","; String 电话=","+tf6.getText().trim()+","; con=DriverManager.getConnection("jdbc:mysqls://localhost:3306/test","root","123456"); sql.executeUpdate("INSERT INTO student2(学号,姓名,性别,专业,地址,电话) VALUES('"+学号+"','"+姓名+"','"+性别+"','"+专业+"','"+地址+"','"+电话+"')"); con.close(); }}
界面已经实现,数据库也连接成功了,只是在实现录入、查询,删除、更新的功能时,在界面上输入却不能改变数据库的数据,求大神帮忙解决,qq:963592544 RMB 20 展开
界面已经实现,数据库也连接成功了,只是在实现录入、查询,删除、更新的功能时,在界面上输入却不能改变数据库的数据,求大神帮忙解决,qq:963592544 RMB 20 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询