这个java代码有什么问题吗,怎么报了那么多错
 package Package1;
import java.sql.*;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;


public class Register  extends JFrame{
    private JPanel contentPane;
    private JTextField textField;
    private JTextField textField_2;
    private JPasswordField passwordField;
    private JTextField textField_1;
    private JTextField textField_3;

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

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Register() throws Exception{
        super("注册界面");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 526, 432);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        textField = new JTextField();
        textField.setBounds(151, 33, 223, 24);
        contentPane.add(textField);
        textField.setColumns(10);

        JLabel label = new JLabel("用户名:");
        label.setBounds(32, 36, 72, 18);
        contentPane.add(label);

        JLabel label_1 = new JLabel("\u5BC6  \u7801\uFF1A");
        label_1.setBounds(32, 88, 72, 18);
        contentPane.add(label_1);

        JLabel label_2 = new JLabel("\u59D3  \u540D\uFF1A");
        label_2.setBounds(32, 138, 72, 18);
        contentPane.add(label_2);

        textField_2 = new JTextField();
        textField_2.setColumns(10);
        textField_2.setBounds(151, 135, 223, 24);
        contentPane.add(textField_2);

        passwordField = new JPasswordField();
        passwordField.setBounds(151, 85, 223, 24);
        contentPane.add(passwordField);

        JLabel label_3 = new JLabel("\u5B66  \u53F7\uFF1A");
        label_3.setBounds(32, 187, 72, 18);
        contentPane.add(label_3);

        textField_1 = new JTextField();
        textField_1.setColumns(10);
        textField_1.setBounds(151, 184, 223, 24);
        contentPane.add(textField_1);

        JLabel label_4 = new JLabel("\u8054\u7CFB\u65B9\u5F0F\uFF1A");
        label_4.setBounds(32, 239, 83, 18);
        contentPane.add(label_4);

        textField_3 = new JTextField();
        textField_3.setColumns(10);
        textField_3.setBounds(151, 236, 223, 24);
        contentPane.add(textField_3);
        JTextArea textArea = new JTextArea();
        textArea.setEditable(false);
        textArea.setBounds(32, 300, 113, 24);
        contentPane.add(textArea);

        JButton button = new JButton("\u5B8C\u6210\u6CE8\u518C");
        button.setBounds(185, 298, 113, 27);
        contentPane.add(button);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String passwords;//密码
                String usernames;//用户名
                String names;//姓名
                String ids;//学号
                String phones;//联系方式
                char[] pswd=passwordField.getPassword();
                passwords=String.valueOf(pswd);
                usernames=textField.getText();
                names=textField_2.getText();
                ids=textField_1.getText();
                phones=textField_3.getText();

                try {
                    Connection1 contosql = null;
                    try {
                        contosql = new Connection1();//连接数据库
                    } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    if(passwords.equals("")||usernames.equals("")||names.equals("")||ids.equals("")||phones.equals("")) {//五个选项任意一个为空的话
                        textArea.setText("请填写完整!");
                    }
                    else {
                        PreparedStatement psql=contosql.con.prepareStatement("insert into userinfo(username,password,name,id,phone)"+"value(?,?,?,?,?)");
                        psql.setString(1, usernames);
                        psql.setString(2, passwords);
                        psql.setString(3, names);
                        psql.setString(4,ids);
                        psql.setString(5, phones);
                        psql.executeUpdate();
                        textArea.setText("注册成功!");
                        psql.close();
                    }
                    contosql.con.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });
    }
}

3个回答

请把报的错报上来吧, 没有错怎么帮你分析?

估计你是直接导入的,没有jar包,项目包名称不对吧。下次记得把错误也粘贴出来。

谢谢各位我已经找出问题了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!