Mysql-is there a problem with the following Java code?

Source: Internet
Author: User
Detail {**** detail; privateJPanelcontentPane; privateJTextFieldtext_confirm; privateJTextFieldtext_usr; privateJTextFieldtext_pwd; private... mysqljava database

Public class Regist extends JFrame implements ActionListener {

/***/Private static final long serialVersionUID = 1L; private JPanel contentPane; private JTextField text_confirm; private JTextField text_usr; private JTextField text_pwd; private JButton btn_save, encrypted; private JLabel user, passwd, confirm; private Connection conn; private Statement statement;/*** Launch the application. */public static void main (String [] args) {EventQueue. invokeLater (new Runnable () {public void run () {try {Regist frame = new Regist (); frame. setVisible (true);} catch (Exception e) {e. printStackTrace () ;}});}/*** Create the frame. */public Regist () {super ("registering a new user"); this. setdefaclocloseoperation (EXIT_ON_CLOSE); this. setVisible (true); setBounds (100,100,450,300); contentPane = new JPanel (); contentPane. setBorder (new EmptyBorder (5, 5, 5, 5); setContentPane (contentPane); contentPane. setLayout (null); user = new JLabel ("user name"); user. setBounds (57, 36, 54, 15); contentPane. add (user); passwd = new JLabel ("password"); passwd. setBounds (57, 76, 54, 15); contentPane. add (passwd); confirm = new JLabel ("confirm password"); confirm. setBounds (57,121, 54, 15); contentPane. add (confirm); text_usr = new JTextField (); text_usr.setBounds (141, 33,155, 21); contentPane. add (text_usr); text_usr.setColumns (10); text_pwd = new JTextField (); text_pwd.setBounds (141, 73,155, 21); contentPane. add (text_pwd); text_pwd.setColumns (10); text_confirm = new JTextField (); text_confirm.setBounds (141,118,155, 21); contentPane. add (text_confirm); text_confirm.setColumns (10); btn_save = new JButton ("OK"); btn_save.setBounds (79,171, 93, 23); contentPane. add (btn_save); this. btn_save.addActionListener (this); btn_cancel = new JButton ("cancel"); btn_cancel.setBounds (256,171, 93, 23); contentPane. add (btn_cancel); this. btn_cancel.addActionListener (this);} public Connection getConnection () throws SQLException {try {Class. forName ("com. mysql. jdbc. driver ");} catch (ClassNotFoundException e) {e. printStackTrace ();} Connection conn = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/sign", "root", "514519"); return conn ;}@ Overridepublic void action=med (ActionEvent e) {if (e. getSource () = btn_save) {if (text_usr.getText (). isEmpty () & text_pwd.getText (). isEmpty () JOptionPane. showMessageDialog (this, "enter the user name and password"); String SQL = "insert into signs values ('" + text_usr.getText () + "," + text_pwd.getText () + "') "; try {conn = getConnection () ;}catch (SQLException e1) {e1.printStackTrace () ;}try {statement = conn. createStatement ();} catch (SQLException e1) {e1.printStackTrace ();} try {statement.exe cuteUpdate (SQL);} catch (SQLException e1) {e1.printStackTrace ();} try {statement. close ();} catch (SQLException e2) {e2.printStackTrace ();} try {conn. close () ;}catch (SQLException e1) {e1.printStackTrace () ;}} if (e. getSource () = btn_cancel ){}}

}
When running, Column count doesn't match value count at row 1
The user and password in my database are of the varchar type.
There is also the quotation mark in this line of code. String SQL = "insert into signs values ('" + text_usr.getText () + "," + text_pwd.getText () + "')"; new users are confused for help

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.