java1996 2016-09-01 06:16 采纳率: 0%
浏览 1945

显示注册成功,也连接成功了数据库,就是数据库里没有更新数据

package edu.jmi.xyh.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Window;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;

import edu.jmi.xyh.bean.Student;
import edu.jmi.xyh.dao.StudentDao;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class RegisterView extends JFrame {

private JPanel contentPane;
private JTextField txID;
private JTextField txName;
private JPasswordField txPw;



/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                RegisterView frame = new RegisterView();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public RegisterView() {
    setTitle("\u5B66\u751F\u4FE1\u606F\u6CE8\u518C");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 361, 327);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel label = new JLabel("\u5B66 \u751F \u4FE1 \u606F \u6CE8 \u518C");
    label.setFont(new Font("宋体", Font.PLAIN, 20));
    label.setBounds(109, 10, 197, 27);
    contentPane.add(label);

    JLabel lblId = new JLabel("\u7528 \u6237 ID\uFF1A");
    lblId.setBounds(78, 47, 73, 15);
    contentPane.add(lblId);

    JLabel label_2 = new JLabel("\u7528 \u6237 \u540D\uFF1A");
    label_2.setBounds(78, 85, 73, 15);
    contentPane.add(label_2);

    JLabel lblNewLabel = new JLabel("\u5BC6    \u7801\uFF1A");
    lblNewLabel.setBounds(78, 124, 73, 15);
    contentPane.add(lblNewLabel);

    txID = new JTextField();
    txID.setBounds(157, 47, 110, 21);
    contentPane.add(txID);
    txID.setColumns(10);

    txName = new JTextField();
    txName.setBounds(161, 82, 106, 21);
    contentPane.add(txName);
    txName.setColumns(10);

    txPw = new JPasswordField();
    txPw.setBounds(161, 121, 106, 21);
    contentPane.add(txPw);

    JButton btnNewButton = new JButton("\u6CE8\u518C");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //完成注册功能
            String id=txID.getText();
            if(id==null||id.length()==0||id.length()>20){
                JOptionPane.showMessageDialog(null, "ID输入不正确!");
            }
            //继续验证用户名和密码
            String pw=txPw.getText();
            String name=txName.getText();
            Student student=new Student();

            student.setStuId(id);
            student.setStuName(name);
            student.setStuPwd(pw);
            StudentDao studentDao=new StudentDao();
            int result=studentDao.save(student);
            if(result==0){
                JOptionPane.showMessageDialog(null, "注册成功!");
                RegisterView.this.dispose();
            }
            else{
                JOptionPane.showMessageDialog(null, "注册失败!");
            }
            System.out.println("id="+id+"pw="+pw);
        }
    });
    btnNewButton.setBounds(47, 183, 93, 23);
    contentPane.add(btnNewButton);

    JButton btnNewButton_1 = new JButton("\u9000\u51FA");
    btnNewButton_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //生成一个对象
            MainView mainView = new MainView();
            //隐藏窗口
            RegisterView.this.setVisible(false);
            mainView.setVisible(true);
        }
    });
    btnNewButton_1.setBounds(194, 183, 93, 23);
    contentPane.add(btnNewButton_1);
}

public void setMainView(MainView mainView) {
    // TODO Auto-generated method stub

}

public void setID(Object id) {
    // TODO Auto-generated method stub

}

}

  • 写回答

3条回答 默认 最新

  • 小范哎呦 2016-09-01 06:26
    关注

    断点跟result呀,studentdao的代码呢

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能