java sql string_java和SQL中的字符串比较(谢谢!)

importjava.awt.Container;importjava.awt.FlowLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.ResultSet...

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

public class Login {

static WindowLogin abs;

public static void main(String[] args) {

abs = new WindowLogin();

}

}

class WindowLogin extends JFrame{

static JTextField name;

JTextField password;

String cc;

JButton jb;

public WindowLogin(){

this.setTitle("登陆界面");

this.setDefaultCloseOperation(3);

this.setLayout(new FlowLayout());

Container c = this.getContentPane();

JLabel j1 = new JLabel("用户名:");

name = new JTextField(10);

JLabel j2 = new JLabel("密码:");

password = new JTextField(10);

jb = new JButton("登陆");

ActionLoad ac = new ActionLoad();

jb.addActionListener(ac);

c.add(j1);

c.add(name);

c.add(j2);

c.add(password);

c.add(jb);

this.pack();

this.setVisible(true);

this.isResizable();

cc = "select * from TestOne";

}

public String getCc() {

return cc;

}

public void setCc(String cc) {

this.cc = cc;

}

public String getName(){

return name.getText();

}

public JTextField getPassword() {

return password;

}

public JButton getJb() {

return jb;

}

}

class DataBaseLogin{

String name;

String password;

ResultSet rs;

public DataBaseLogin(String sql){

DataBase01 dbcon = new DataBase01();

Connection con = dbcon.AddDriver();

try {

Statement st = con.createStatement();

ResultSet rs = st.executeQuery(sql);

while(rs.next()){

name = rs.getString(1);

if(rs.getString(1)==Login.abs.getName()){

password = rs.getString(2);

if(rs.getString(4).equals(Login.abs.getPassword().getText())){

JOptionPane.showConfirmDialog(null, "登陆成功!");

break;

}

}

else{

continue;

}

}

JOptionPane.showConfirmDialog(null, "登陆失败!");

}

catch (SQLException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

}

}

}

class ActionLoad implements ActionListener{

public void actionPerformed(ActionEvent e) {

if(e.getSource().equals(Login.abs.getJb())){

new DataBaseLogin(Login.abs.getCc());

}

}

}

在数据库中获得到的int型可以正常比较,但是,比较字符串的时候就不能正常显示。请高手指点!(Eclipse编译通过)

展开

相关资源:SQL转成java字符串
已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页