java数据库中 怎么将登陆界面输入的账号密码跟数据库账号密码比较是否一致,如果是就显示成功,否则失败
我是用SQL2005的下面是我的登录界面代码importjava.io.*;importjava.util.*;importjava.awt.*;importjava.a...
我是用SQL2005的 下面是我的登录界面代码
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
import java.util.Date;
import java.text.*;
import java.sql.*;
public class ClientPasswords extends JFrame
{
JFrame frame;
Container content;
JLabel user;
JLabel passwords;
TextField textuser;
TextField textpasswords;
JButton button;
JTextArea txtusers;
GridBagLayout gl;
GridBagConstraints gbc;
public ClientPasswords(){
gl = new GridBagLayout();
gbc = new GridBagConstraints();
content = this.getContentPane();
content.setLayout(gl);
user = new JLabel("用户名");
passwords = new JLabel("密码");
textuser = new TextField(10);
textpasswords = new TextField(10);
txtusers = new JTextArea();
textpasswords.setEchoChar('*');
button = new JButton("确定");
ClickListener listen = new ClickListener();
button.addActionListener(listen);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 5;
gl.setConstraints(user,gbc);
content.add(user);
gbc.gridx = 4;
gbc.gridy = 5;
gl.setConstraints(textuser,gbc);
content.add(textuser);
gbc.gridx = 1;
gbc.gridy = 8;
gl.setConstraints(passwords,gbc);
content.add(passwords);
gbc.gridx = 4;
gbc.gridy = 8;
gl.setConstraints(textpasswords,gbc);
content.add(textpasswords);
gbc.gridx = 10;
gbc.gridy = 32;
gl.setConstraints(button,gbc);
content.add(button);
gbc.gridx = 20;
gbc.gridy = 40;
gl.setConstraints(txtusers,gbc);
content.add(txtusers);
this.setSize(300,250);
this.setVisible(true);
}
class ClickListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String str,str2;
str=textuser.getText();
System.out.println("用户名:"+str);
str2=textpasswords.getText();
System.out.println("密码:"+str2);
txtusers.setText("结果:"+"\n");
searchInfo();
}
}
public void searchInfo(){
Connection con = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Chankinghom");
Statement stat = con.createStatement();
ResultSet rs = null;
rs = stat.executeQuery("select * from users ");
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}
public static void main(String[]args)throws IOException{
ClientPasswords cp = new ClientPasswords();
}
}
数据库中的表格名字叫users,分别有uname,upassword,uemail三个字段 展开
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
import java.util.Date;
import java.text.*;
import java.sql.*;
public class ClientPasswords extends JFrame
{
JFrame frame;
Container content;
JLabel user;
JLabel passwords;
TextField textuser;
TextField textpasswords;
JButton button;
JTextArea txtusers;
GridBagLayout gl;
GridBagConstraints gbc;
public ClientPasswords(){
gl = new GridBagLayout();
gbc = new GridBagConstraints();
content = this.getContentPane();
content.setLayout(gl);
user = new JLabel("用户名");
passwords = new JLabel("密码");
textuser = new TextField(10);
textpasswords = new TextField(10);
txtusers = new JTextArea();
textpasswords.setEchoChar('*');
button = new JButton("确定");
ClickListener listen = new ClickListener();
button.addActionListener(listen);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 5;
gl.setConstraints(user,gbc);
content.add(user);
gbc.gridx = 4;
gbc.gridy = 5;
gl.setConstraints(textuser,gbc);
content.add(textuser);
gbc.gridx = 1;
gbc.gridy = 8;
gl.setConstraints(passwords,gbc);
content.add(passwords);
gbc.gridx = 4;
gbc.gridy = 8;
gl.setConstraints(textpasswords,gbc);
content.add(textpasswords);
gbc.gridx = 10;
gbc.gridy = 32;
gl.setConstraints(button,gbc);
content.add(button);
gbc.gridx = 20;
gbc.gridy = 40;
gl.setConstraints(txtusers,gbc);
content.add(txtusers);
this.setSize(300,250);
this.setVisible(true);
}
class ClickListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String str,str2;
str=textuser.getText();
System.out.println("用户名:"+str);
str2=textpasswords.getText();
System.out.println("密码:"+str2);
txtusers.setText("结果:"+"\n");
searchInfo();
}
}
public void searchInfo(){
Connection con = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Chankinghom");
Statement stat = con.createStatement();
ResultSet rs = null;
rs = stat.executeQuery("select * from users ");
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}
public static void main(String[]args)throws IOException{
ClientPasswords cp = new ClientPasswords();
}
}
数据库中的表格名字叫users,分别有uname,upassword,uemail三个字段 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询