关于数据库出错了....高手帮忙下
下面就是我的登陆对话框中当点击登陆时 触发的代码
为什么从数据库中取出来的密码是乱码啊?
public void checkfill() {
String lname = Lname.getText();
char lpass[] = Lpass.getPassword();
if (lname.length() == 0) {
JOptionPane.showMessageDialog(this, "请输入用户名 ");
} else if (lpass.length == 0) {
JOptionPane.showMessageDialog(this, "请输入密码 ");
} else {
Logincon();
}
}
public void Logincon() {
String url = "jdbc:mysql://localhost:3306/lucky ";
sqlname = "root ";
sqlpass = "zhangyang ";
try {
Class.forName( "com.mysql.jdbc.Driver ");
con = DriverManager.getConnection(url, sqlname, sqlpass);
// System.out.println( "1 run ing now ");
} catch (
ClassNotFoundException e) {
System.out.println( "装载驱动程序失败 ");
e.printStackTrace();
System.exit(1);
} catch (
SQLException e) {
System.err.println( "无法连接数据库 ");
e.getMessage();
}
try {
lname = Lname.getText();
String checkname = "select * from user where name= " + lname + " ";
/*
* String strsql = "select * from user where (name= ' " + lname + " '
* and pass= ' " + lpass + " ') ";
*/
stmt = con.createStatement();
rs = stmt.executeQuery(checkname);
boolean flag = rs.next();
if (flag) {
lpass = Lpass.getPassword();
String checkpass = "select * from user where name= " + lname
+ " ";
stmt = con.createStatement();
rs = stmt.executeQuery(checkpass);
rs.next();
char[] repass = rs.getString(1).toCharArray();
System.out.println(repass.toString());
boolean x=Arrays.equals(lpass,repass);
if (x) {
flags = 1;
} else {
JOptionPane.showMessageDialog(this, "密码错误 ");
Lpass.setText( " ");
}
}
else {
JOptionPane.showMessageDialog(this, "用户名不存在 ");
Lname.setText( " ");
Lpass.setText( " ");
return;
}
con.close();
rs.close();
stmt.close();
} catch (SQLException e) {
e.getStackTrace();
}
}
还有就是我在程序中注册用户后,存在数据库中也是乱码
表的结构如下
mysql> desc user;
+--------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |