最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

mysql-下面的Java代碼有問(wèn)題嗎

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-09 16:52:16
文檔

mysql-下面的Java代碼有問(wèn)題嗎

mysql-下面的Java代碼有問(wèn)題嗎:mysqljava數(shù)據(jù)庫(kù) public class Regist extends JFrame implements ActionListener {/** * */private static final long serialVersionUID = 1L;private JPanel contentPane;private JTextField
推薦度:
導(dǎo)讀mysql-下面的Java代碼有問(wèn)題嗎:mysqljava數(shù)據(jù)庫(kù) public class Regist extends JFrame implements ActionListener {/** * */private static final long serialVersionUID = 1L;private JPanel contentPane;private JTextField

mysqljava數(shù)據(jù)庫(kù)

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,btn_cancel;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("注冊(cè)新用戶"); this.setDefaultCloseOperation(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.setBounds(57, 36, 54, 15); contentPane.add(user); passwd = new JLabel("密 碼"); passwd.setBounds(57, 76, 54, 15); contentPane.add(passwd); confirm = new JLabel("確認(rèn)密碼"); 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("確定"); btn_save.setBounds(79, 171, 93, 23); contentPane.add(btn_save); this.btn_save.addActionListener(this); btn_cancel = new JButton("取消"); 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 actionPerformed(ActionEvent e) { if(e.getSource()==btn_save){ if(text_usr.getText().isEmpty()&&text_pwd.getText().isEmpty())  JOptionPane.showMessageDialog(this, "請(qǐng)?zhí)顚?xiě)用戶名和密碼"); 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.executeUpdate(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){ }}

}
運(yùn)行的時(shí)候說(shuō)Column count doesn't match value count at row 1
我數(shù)據(jù)庫(kù)中的user 和password都是varchar類型
還有就是這行代碼中的引號(hào)問(wèn)題 String sql="insert into signs values ('"+text_usr.getText()+","+text_pwd.getText()+"')"; 新手有點(diǎn)迷糊 求幫助

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

mysql-下面的Java代碼有問(wèn)題嗎

mysql-下面的Java代碼有問(wèn)題嗎:mysqljava數(shù)據(jù)庫(kù) public class Regist extends JFrame implements ActionListener {/** * */private static final long serialVersionUID = 1L;private JPanel contentPane;private JTextField
推薦度:
標(biāo)簽: 錯(cuò)誤 下面 問(wèn)題
  • 熱門(mén)焦點(diǎn)

最新推薦

猜你喜歡

熱門(mén)推薦

專題
Top