📄 zhucedb.java
字号:
package liaotshi2;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class zhucedb extends JFrame implements ActionListener {
JPanel panel;
JLabel id;
JLabel ps,ps2;
JLabel email;
JTextField idtext;
JTextField pstext;
JTextField ps2text;
JTextField emailtext;
JButton b1;
JButton b2;
JButton b3, add;
int n = 1;
int m=0;
public zhucedb() {
// panel=new JPanel();
super("注册登陆");
panel = new JPanel(new BorderLayout());
id = new JLabel("用 户 名:");
ps = new JLabel("密 码:");
ps2 = new JLabel("确认密码:");
email = new JLabel("E_Mail:");
idtext = new JTextField(7);
pstext = new JTextField(7);
ps2text = new JTextField(7);
emailtext = new JTextField(7);
// FlowLayout f=new FlowLayout(FlowLayout.LEFT);
panel.setLayout(new FlowLayout());
b1 = new JButton("注册");
b2 = new JButton("返回");
//b3 = new JButton("下一条");
// add = new JButton("添加");
b1.addActionListener(this);
b2.addActionListener(this);
//b3.addActionListener(this);
// 为b1注册监听程序
// JPanel p1 = new JPanel();
// JPanel p2 = new JPanel();
// JPanel p3 = new JPanel();
// JPanel p4 = new JPanel();
panel.add(id);
panel.add(idtext);
panel.add(ps);
panel.add(pstext);
panel.add(ps2);
panel.add(ps2text);
panel.add(email);
panel.add(emailtext);
//p3.add(age);
//p3.add(agetext);
panel.add(b1);
panel.add(b2);
// p4.add(b3);
// panel.add(p1);
// panel.add(p2, "Center");
// panel.add(p3, "Center");
// panel.add(p4, "North");
getContentPane().add(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(230, 300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
// JOptionPane.showMessageDialog(null,"hello");
//注册
if (e.getSource() == b1) {
// JOptionPane.showMessageDialog(null,"hello");
zc();
}
if (e.getSource() == b2) {
// JOptionPane.showMessageDialog(null,"world");
new chatClient();
this.dispose();
}
// if (e.getSource() == b3) {
// // JOptionPane.showMessageDialog(null,"world");
// // fw3();
// }
}
public void zc() {
Connection con=null ;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= DriverManager.getConnection("jdbc:odbc:myDSN",
"sa", "niit");
con.setAutoCommit(false);//不让系统自动提交事务
CallableStatement cs=con.prepareCall("{call prcInsert(?,?,?)}");
cs.setString(1, idtext.getText());
cs.setString(2, pstext.getText());
cs.setString(3, "23");
int result=cs.executeUpdate();
Statement stat=con.createStatement();
ResultSet rs=stat.executeQuery("select count(*) from biao");
rs.next();
int count=rs.getInt(1);
System.out.println(count);
if(result>0&&count<6)
{
con.commit();
JOptionPane.showMessageDialog(null, "注册成功");
}
else
{
con.rollback();
JOptionPane.showMessageDialog(null, "本聊天室注册已满!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
try {
con.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}
public static void main(String[] args) {
new zhucedb();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -