📄 useradd.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class UserAdd extends JFrame implements ActionListener
{
JLabel[] Jl={new JLabel(" 名字"),new JLabel(" 地址"),
new JLabel(" 邮政编码"),new JLabel(" 电话"),new JLabel(" 身份证号")
};
JTextField []Jt={new JTextField(8),new JTextField(8),
new JTextField(8),new JTextField(8),new JTextField(8)
};
Container c;
JButton []Jb={new JButton("确认"),new JButton("取消")
};
public UserAdd()
{
super("开设帐户");
c=getContentPane();
c.setLayout(new GridLayout(6,2));
for(int i=0;i<Jl.length;i++)
{
c.add(Jl[i]);
c.add(Jt[i]);
}
c.add(Jb[0]);
c.add(Jb[1]);
Jb[0].addActionListener(this);
Jb[1].addActionListener(this);
setSize(240,180);
show();
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==Jb[0])
{
String user=Jt[1].getText();
if((user.length()==0))
{
System.out.println("用户名不能为空!");
}
else
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//声明驱动程序
String url="jdbc:odbc:info";//指定数据源名
Connection con=DriverManager.getConnection(url);//连接数据库
PreparedStatement stm=con.prepareStatement
("insert into 客户信息 values(?,?,?,?)");
ResultSet result=stm.executeQuery();
//下面为置插入语句中的参数值
String count=null;
while(result.next())
{
count=result.getString(1);
}
int ct=Integer.parseInt(count);
ct++;
stm.setString(1,(""+ct));
stm.setString(2,"888888");
stm.setString(3,"user");
stm.setString(4,"0");
try
{
stm.executeQuery();
}
//执行插入操作
catch(Exception edfh)
{}
try
{
stm.executeQuery();
}catch(Exception ev){}
con.close();
}catch(Exception ev){}
}
this.dispose();
new NewUser();
}
else
{
int n = JOptionPane.showConfirmDialog(
this, "是否真的要退出", "退出窗口",
JOptionPane.YES_NO_OPTION );
if( n==JOptionPane.YES_OPTION )
{
this.dispose();
new Login();
}
}
}
public void windowClosed(WindowEvent e)
{
new Login();
}
public void windowActivated(WindowEvent e)
{
}
public void windowClosing(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowIconified(WindowEvent e)
{
}
public void windowOpened(WindowEvent e)
{
}
public static void main(String args[])
{
new UserAdd();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -