下面就是我的登陆对话框中当点击登陆时 触发的代码为什么从数据库中取出来的密码是乱码啊?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 |
+--------+-----------+------+-----+---------+-------+
| name   | char(50)  | NO   | PRI | NULL    |       |
| pass   | char(20)  | NO   |     | NULL    |       |
| mail   | char(80)  | NO   |     | NULL    |       |
| adress | char(100) | NO   |     | NULL    |       |
+--------+-----------+------+-----+---------+-------+
4 rows in set (0.08 sec)在数据库中存储为mysql> select * from user;
+-----------+------------+---------------+----------------+
| name      | pass       | mail          | adress         |
+-----------+------------+---------------+----------------+
| 111       | [C@9ed927  | [email protected]   | 111            |
| 12        | [C@112f614 | [email protected]   | 111            |
| 121       | [C@12a54f9 | [email protected]   | 121            |
| 121313213 | [C@19106c7 | [email protected]   | 111            |
| 123       | [C@723d7c  | [email protected]   | kjnh           |
| 1231      | [C@13bad12 | [email protected]   | kjnh           |
| 12313     | [C@13582d  | [email protected]   | 122            |
| 198827    | [C@1975b59 | [email protected]   | 111            |
| 207       | [C@aeffdf  | [email protected]   | kjnh           |
| 208       | [C@b42cbf  | [email protected]   | kjnh           |
在这里用户名和密码一样,但是在数据库中显示不一样谢谢改正...