java中的字符串比较问题(关键是persontyDD为啥老是不等于fu呢?) 5
importjavax.swing.*;importjava.awt.*;importjava.sql.*;importjava.awt.event.*;importja...
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JFrameDemo
{String passwordD=null;
public static String persontyDD=null;
public JFrameDemo(){
final JFrame frame1 = new JFrame("超市管理系统登陆界面");
final JButton button = new JButton("登陆");
JLabel labelName = new JLabel("请输入账号");
JLabel labelNumber = new JLabel("请输入密码");
final JTextField tfName = new JTextField(12);
final JTextField tfNumber = new JTextField(12);
JMenuBar menubar = new JMenuBar();
JMenu mu = new JMenu("功能");
JMenuItem help = new JMenuItem("帮助");
JMenuItem quet = new JMenuItem("退出");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Connection con;
Statement sql;
ResultSet rs = null;String fu="超级用户";
if(e.getSource()==button)
{
String idin = tfName.getText();
String keyin = tfNumber.getText();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=Supermarket";
String user="sa";
String password="123456";
con=DriverManager.getConnection(url,user,password);
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM password where ID='"
+ idin + "'");
while (rs.next()) {
passwordD= rs.getString(2); persontyDD= rs.getString(3);
}
con.close();
} catch (Exception g)
{System.out.println(g);}
if (persontyDD!=null)
{
frame1.dispose();
ViewDemo frame=new ViewDemo();
System.out.println(persontyDD);
if(persontyDD.equals(fu)){
System.out.println("1");
}}}
else
{
frame1.dispose();
Close frame=new Close();
}
}} );
mu.add(help);
mu.add(quet);
menubar.add(mu);
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JPanel p5 = new JPanel(new BorderLayout());
JPanel p6 = new JPanel(new GridLayout(3, 1));
p1.add(labelName);
p1.add(tfName);
p2.add(labelNumber);
p2.add(tfNumber);
p4.add(menubar);
p3.add(button);
p6.add(p1);
p6.add(p2);
p6.add(p3);
p5.add(p4, BorderLayout.NORTH);
p5.add(p6, BorderLayout.CENTER);
frame1.getContentPane().add(p5, BorderLayout.CENTER);
frame1.pack();
frame1.setVisible(true);}
public static void main(String args[]) {
new JFrameDemo();
}} 展开
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JFrameDemo
{String passwordD=null;
public static String persontyDD=null;
public JFrameDemo(){
final JFrame frame1 = new JFrame("超市管理系统登陆界面");
final JButton button = new JButton("登陆");
JLabel labelName = new JLabel("请输入账号");
JLabel labelNumber = new JLabel("请输入密码");
final JTextField tfName = new JTextField(12);
final JTextField tfNumber = new JTextField(12);
JMenuBar menubar = new JMenuBar();
JMenu mu = new JMenu("功能");
JMenuItem help = new JMenuItem("帮助");
JMenuItem quet = new JMenuItem("退出");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Connection con;
Statement sql;
ResultSet rs = null;String fu="超级用户";
if(e.getSource()==button)
{
String idin = tfName.getText();
String keyin = tfNumber.getText();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=Supermarket";
String user="sa";
String password="123456";
con=DriverManager.getConnection(url,user,password);
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM password where ID='"
+ idin + "'");
while (rs.next()) {
passwordD= rs.getString(2); persontyDD= rs.getString(3);
}
con.close();
} catch (Exception g)
{System.out.println(g);}
if (persontyDD!=null)
{
frame1.dispose();
ViewDemo frame=new ViewDemo();
System.out.println(persontyDD);
if(persontyDD.equals(fu)){
System.out.println("1");
}}}
else
{
frame1.dispose();
Close frame=new Close();
}
}} );
mu.add(help);
mu.add(quet);
menubar.add(mu);
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JPanel p5 = new JPanel(new BorderLayout());
JPanel p6 = new JPanel(new GridLayout(3, 1));
p1.add(labelName);
p1.add(tfName);
p2.add(labelNumber);
p2.add(tfNumber);
p4.add(menubar);
p3.add(button);
p6.add(p1);
p6.add(p2);
p6.add(p3);
p5.add(p4, BorderLayout.NORTH);
p5.add(p6, BorderLayout.CENTER);
frame1.getContentPane().add(p5, BorderLayout.CENTER);
frame1.pack();
frame1.setVisible(true);}
public static void main(String args[]) {
new JFrameDemo();
}} 展开
4个回答
展开全部
你可以打个断点跟踪一下,这样的小问题要学会自己解决。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询