java职员登录功能代码 java登陆功能代码( 二 )


} catch
(ClassNotFoundException e) {
e.printStackTrace();
}
String
url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user =
"scott";
String password = "tiger";
Connection conn =
null;
String sql = "Insert Into USERINFO
values(?,?,?)";
PreparedStatement pst =
null;
//判断登陆名是否已经存在
Statement s = null;
ResultSet rs =
null;
String sql_ck = "Select LOGINNAME FROM USERINFO";
try
{
conn = DriverManager.getConnection(url, user, password);
pst =
conn.prepareStatement(sql);
pst.setString(1,
u.getName());
pst.setString(2, u.getLoginname());
pst.setString(3,
u.getLoginpsw());
//判断登陆名是否已经存在
s =
conn.createStatement();
rs =
s.executeQuery(sql_ck);
while(rs.next()){//为什么用 rs.getString(2)会提示
无效的索引呢
if( rs.getString("LOGINNAME").equals(u.getLoginname())
){
System.out.println("登陆名已经存在,注册失败");
break;
}else{
pst.executeUpdate();
System.out.println("注册成功");
break;
}
}
}
catch (SQLException e) {
e.printStackTrace();
}finally{
try
{
rs.close();
pst.close();
s.close();
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
//main界面//
//数据库中表的结构式这样
//name(用户名 , 用于显示),
//loginname(登录名,即登陆时输入的ID)
//loginpsw(登陆时输入的密码)
package
登陆判断;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int chos = 0;
Scanner sc = new
Scanner(System.in);
System.out.println("\t\t登陆请按1\t\t注册请按2");
chos =
sc.nextInt();
switch(chos){
case 1:
Check.checkUser(In.getUser());break;
case 2:
Register.registUser(In.registerUser());break;
default:
System.out.println("请输入正确的选择");break;
}
}
}
实现界面登陆 , 退出功能的java代码怎么写?CS结构系统的退出如下:public void init() {\x0d\x0athis.setTitle("用户登录界面");\x0d\x0athis.add(createCenterPane());\x0d\x0athis.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);\x0d\x0athis.setSize(new Dimension(450, 335));\x0d\x0athis.setLocationRelativeTo(null);\x0d\x0a// this.setVisible(true);\x0d\x0athis.addWindowListener(new WindowAdapter() {\x0d\x0apublic void windowClosing(WindowEvent e) {\x0d\x0aint choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",\x0d\x0a"系统提示:", JOptionPane.YES_NO_OPTION);\x0d\x0aif (choose == JOptionPane.YES_OPTION) {\x0d\x0aSystem.exit(1);\x0d\x0a}\x0d\x0a}\x0d\x0a});\x0d\x0a }其中this为JFrame对象 。BS结构的退出直接用windows.close()方法就行了!
登陆界面的java代码怎么写?import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class LoginFrm extends JFrame implements ActionListener
{
JLabel lbl1=new JLabel("用户名");
JLabel lbl2=new JLabel("密码");
JTextField txt=new JTextField(15);
JPasswordField pf=new JPasswordField();
JButton btn1=new JButton("确定");
JButton btn2=new JButton("取消");
public LoginFrm()
{
this.setTitle("登陆");
JPanel jp=(JPanel)this.getContentPane();
jp.setLayout(new GridLayout(3,2,10,10));
jp.add(lbl1);jp.add(txt);
jp.add(lbl2);jp.add(pf);
jp.add(btn1);jp.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{

推荐阅读