package ms; //���û�ע�� import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class New_User extends JFrame{ JLabel tips1,tips2,tips3,tips4; JTextField wbk1,wbk2,wbk3,wbk4; JButton check_btn; JPanel mb1,mb2,mb3,mb4; String username; Connection conn=null; public New_User() { tips1=new JLabel("��ʾ���������û���"); tips2=new JLabel("��ʾ�����루5λ��"); tips3=new JLabel("��ʾ���������Ա�"); tips4=new JLabel("��ʾ��������绰"); wbk1=new JTextField(6); wbk2=new JTextField(6); wbk3=new JTextField(6); wbk4=new JTextField(9); check_btn=new JButton("�ύ"); check_btn.addActionListener(new checkListen()); mb1=new JPanel(); mb2=new JPanel(); mb1.add(wbk1);mb1.add(tips1); mb1.add(wbk2);mb1.add(tips2); mb1.add(wbk3);mb1.add(tips3); mb1.add(wbk4);mb1.add(tips4); mb2.add(check_btn,BorderLayout.NORTH); mb1.setLayout(new GridLayout(4,2)); this.add(mb1,BorderLayout.CENTER);this.add(mb2,BorderLayout.SOUTH); this.setVisible(true); this.setSize(350,200); this.setLocationRelativeTo(null);//������ʾ } class checkListen implements ActionListener { @Override public void actionPerformed(ActionEvent e) { // TODO �Զ���ɵķ������ IDB(); pipei(); if(wbk1.getText().equals("")||wbk2.getText().equals(""))//�ж��ı����Ƿ�Ϊ��һ��Ҫ��equals {JOptionPane.showMessageDialog(null, "�û�������벻��Ϊ�գ�");} else if(username!=null) { JOptionPane.showMessageDialog(null, "�û����ѱ�ע�ᣡ"); } else{ charu(); JOptionPane.showMessageDialog(null, "ע��ɹ���"); } } } //������ݿ� public void IDB() { try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String url="jdbc:sqlserver://localhost:1433;DatabaseName=��ѧ��У��ʳ����"; String user="sa"; String passWord="lch"; conn=DriverManager.getConnection(url,user,passWord); }catch(Exception e){ e.printStackTrace(); } } //��ȡ��ݿ�����Ӧ�� public void pipei() { try{ String usname = wbk1.getText(); Statement state = conn.createStatement(); username=null;//�ǵó�ʼ�� String sql = "select username from login where username = '"+usname+"'"; ResultSet res = state.executeQuery(sql); while(res.next()) { username = res.getString("username"); } //conn.close(); }catch(Exception e){ e.printStackTrace(); } } //������ public void charu() { String uname=wbk1.getText(); String psword=wbk2.getText(); String sex=wbk3.getText(); String phone=wbk4.getText(); try{ Statement statement=conn.createStatement(); statement.execute("insert into login values('"+uname+"','"+psword+"','"+sex+"','"+phone+"')"); conn.close(); }catch(Exception e){ } } }

Demo1111 LV30
2021年12月12日
tiashishiwo LV5
2021年7月3日
fdsvsfds LV2
2021年3月16日
此刀名为秋水 LV1
2021年2月20日
freedom2017 LV14
2020年6月2日
狗比lc LV1
2020年1月2日
hanyuiqng LV9
2019年12月24日
啊浩啊 LV7
2019年9月19日
CJ6872400 LV1
2019年7月27日
mangen LV1
2019年6月25日

就爱吃饺子啊 LV1
2024年10月21日
aaaaaaaaa4 LV1
2024年9月19日
ZALZXB20030525
2024年7月1日
暂无贡献等级
18306681497 LV1
2024年6月27日
cx20031221
2024年6月5日
暂无贡献等级
林灵123456 LV8
2024年6月3日
2860615178 LV4
2024年5月29日
R8sixsix LV1
2024年2月27日
廖业贵 LV18
2024年2月23日
adyxhss LV3
2023年12月25日