?? 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 + -