java学生登录系统代码 java学生登录系统代码查询( 四 )


count=2;
}
else if(e.getActionCommand().equals("删除"))
{
query="delete from students where XSB="+num+" and name="+"'"+name+"'";
count=3;
}
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
String query1=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
if(count==1)
{
query1="select * from students where XSB="+num+";";
rs=stmt.executeQuery(query1);
if(rs.next())
textField_3.setText("已经由此记录,不能追加!");
else
{
stmt.executeUpdate(query);
textField_3.setText("已经追加完成!");
}
}
else if(2==count)
{
stmt.executeQuery(query);
rs=stmt.executeQuery(query);
if(rs.next())
{
textField_3.setText("已查找到此记录!");
}
else
{
textField_3.setText("没有此记录,可以追加!");
}
}
else if(3==count)
{
query1="select * from students where XSB="+num+" and name="+"'"+name+"'";
rs=stmt.executeQuery(query1);
if(rs.next())
{
stmt.executeUpdate(query);
textField_3.setText("已删除此记录!");
}
else
textField_3.setText("无此记录!");
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally{
//关闭资源
if(stmt!=null){
try {
stmt.close();
} catch (Exception e2) {
// TODO: handle exception
}
stmt=null;
}
if(con!=null){
try {
con.close();
} catch (Exception e2) {
// TODO: handle exception
}
con=null;
}
}
}
}
用java写一个登陆界面代码 。概述
具体框架使用jframejava学生登录系统代码,文本框组件java学生登录系统代码:JTextField;密码框组件:JPasswordField;标签组件:JLabel;复选框组件:JCheckBox;单选框组件:JRadioButton;按钮组件JButton 。
登录界面:
代码实例
import javax.swing.*;
import java.awt.*;//导入必要java学生登录系统代码的包
public class denglu extends JFrame{
JTextField jTextField ;//定义文本框组件
JPasswordField jPasswordField;//定义密码框组件
JLabel jLabel1,jLabel2;
JPanel jp1,jp2,jp3;
JButton jb1,jb2; //创建按钮
public denglu(){
jTextField = new JTextField(12);
jPasswordField = new JPasswordField(13);
jLabel1 = new JLabel("用户名");
jLabel2 = new JLabel("密码");
jb1 = new JButton("确认");
jb2 = new JButton("取消");
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
//设置布局
this.setLayout(new GridLayout(3,1));
jp1.add(jLabel1);
jp1.add(jTextField);//第一块面板添加用户名和文本框
jp2.add(jLabel2);
jp2.add(jPasswordField);//第二块面板添加密码和密码输入框
jp3.add(jb1);
jp3.add(jb2); //第三块面板添加确认和取消
//jp3.setLayout(new FlowLayout());//因为JPanel默认布局方式为FlowLayoutjava学生登录系统代码,所以可以注销这段代码.
this.add(jp1);
this.add(jp2);
this.add(jp3);//将三块面板添加到登陆框上面
//设置显示
this.setSize(300, 200);
//this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setTitle("登陆");
}
public static void main(String[] args){
new denglu();
}
}
拓展内容

推荐阅读