当前位置: 代码迷 >> Java相关 >> 求助用户名验证问题!
  详细解决方案

求助用户名验证问题!

热度:258   发布时间:2007-07-31 15:23:36.0
求助用户名验证问题!


public void jButton1_actionPerformed(ActionEvent e) {
String Sql = "";
Statement st = sql.Connect();
String name = this.jTextField1.getText();
char[] x = this.jPasswordField1.getPassword();
String pwd = new String(x);
if (this.jTextField1.getText() != null ||
this.jPasswordField1.getPassword() != null) {

Sql = "INSERT INTO info (UName,UPwd) values ('" + name +
"','" + pwd + "')";
} else {
JOptionPane.showMessageDialog(this, "请输入用户名或密码");
}

try {
st.executeUpdate(Sql);
st.close();
sql.close();
} catch (SQLException ex) {
}
}

红色部分要怎么写,才能使我的验证框在没有任何数值的情况下提示我
输入用户名和密码呢?
知道的朋友帮帮忙,万分感谢

搜索更多相关的解决方案: String  用户名  验证  null  

----------------解决方案--------------------------------------------------------
public void jButton1_actionPerformed(ActionEvent e)哪来的这个方法.自己定义的?
//假如你确定 JButton bt=new Buttou("确定");

public void actionPerformed(ActionEvent e)
{
if(e.getSoure==bt)
if (jTextField1.getText() != null || jPasswordField1.getPassword() != null)
JOptionPane.showMessageDialog(... "请输入用户名或密码");
}
----------------解决方案--------------------------------------------------------

public void jButton1_actionPerformed(ActionEvent e)哪来的这个方法.自己定义的?
//假如你确定//这是用JBuilder设计的按键双击时自动生成的方法名
因为不知道怎么把图才能帖上去

这个按钮起到了在数据库中注册信息的功能,
所以不能注册空信息进入数据库
我的意思是如果用户名或密码没输入则弹出提示框要求用户输入,
否则注册不成功。


----------------解决方案--------------------------------------------------------
if(jTextFiled.getText().matches("[ ]*")||jPasswordField.getText().matches("[ ]*")){

JOPationPane.showMessageDialog();
}else {
你自己的代码
}
----------------解决方案--------------------------------------------------------
回复:(狂放不羁)if(jTextFiled.getText().matches(...

在我把判断密码为空的那一项删除后,在不输入任何信息的情况下会提示我输入用户名或密码了,
当我加上判断密码的那句就会报错,而且在jPasswordField1中的gettext方法已经过时了,只能用getPassword
方法,但是后面的matches方法却点不出来,还有就是请问matches方法是什么意思?
----------------解决方案--------------------------------------------------------

String password= new String( passwordField.getPassword())
if(jTextFiled.getText().matches("[ ]*")||password.matches("[ ]*")){

JOPationPane.showMessageDialog();
}else {
你自己的代码
}

matches()是去匹配一个正则表达式。如果匹配0个或者多个空格就当作密码没有输入。。要把char[] 转化为String


----------------解决方案--------------------------------------------------------
回复:(狂放不羁)String password= new String( pas...
已经好了,现在不输入密码也会报错了,非常感谢


----------------解决方案--------------------------------------------------------
不用客气呵呵。。
----------------解决方案--------------------------------------------------------
  相关解决方案