大家帮忙解决一下,在 System.out.println(e.toString());这段代码里面out出问题,只要是有一段System.out.println(e.toString());的都会出这样的问题。
USER.JAVA
package com.bar.db;
import java.sql.*;
public class User extends ExecuteDB
{
//定义类成员变量
private long userid;
private String uname;
private String name;
private String pwd;
private String sex;
private String email;
private String address;
private String tel;
private String birth;
private String post;
private String safequestion;
private String safeanswer;
private String role;
private String money;
private String createtime;
private String strSql;
//构造函数,对成员变量进行初始化赋值
public User()
{
super();
this.userid=0;
this.uname="";
this.name="";
this.pwd="";
this.sex="";
this.email="";
this.address="";
this.tel="";
this.birth="";
this.post="";
this.safequestion="";
this.safeanswer="";
this.role = "会员";
this.money="0";
java.util.Date NowTime = new java.util.Date();
this.createtime = NowTime.toLocaleString();
this.strSql="";
}
//添加新用户,往users数据表中添加一条新记录
public boolean add()
{
this.strSql="insert into user ";
this.strSql=this.strSql + "(uname,name,pwd,sex,email,address,tel,birth,post,safequestion,safeanswer,createtime) ";
this.strSql=this.strSql + "values('" + this.uname + "','" + this.name + "','" + this.pwd + "','" + this.sex + "','" + this.email + "','" + this.address + "','" + this.tel + "','" + this.birth + "','" + this.post + "','" + this.safequestion + "','" + this.safeanswer + "','" + this.createtime + "')";
boolean isAdd = super.exeSql(this.strSql);
return isAdd;
}
//修改UserID对应的用户的信息
public boolean modify_info()
{
this.strSql="update user set";
this.strSql=this.strSql + " name=" + "'" + this.name + "',";
this.strSql=this.strSql + " sex=" + "'" + this.sex + "',";
this.strSql=this.strSql + " email=" + "'" + this.email + "',";
this.strSql=this.strSql + " address=" + "'" + this.address + "',";
this.strSql=this.strSql + " tel=" + "'" + this.tel + "',";
this.strSql=this.strSql + " birth=" + "'" + this.birth + "',";
this.strSql=this.strSql + " post=" + "'" + this.post + "',";
this.strSql=this.strSql + " safequestion=" + "'" + this.safequestion + "',";
this.strSql=this.strSql + " safeanswer=" + "'" + this.safeanswer + "',";
this.strSql=this.strSql + " createtime=" + "'" + this.createtime + "'";
this.strSql=this.strSql + " money=" + "'" + this.money + "'";
this.strSql=this.strSql + " where userid='" + this.userid + "'";
boolean isUpdate = super.exeSql(this.strSql);
return isUpdate;
}
//修改UserID对应的用户的密码
public boolean modify_UserPassword()
{
this.strSql="update users set ";
this.strSql=this.strSql + "pwd=" + "'" + this.pwd + "'";
this.strSql=this.strSql + " where userid='" + this.userid + "'";
boolean isUpdatekey = super.exeSql(this.strSql);
return isUpdatekey;
}
//获得UserID对应的用户的信息,将这些信息赋值给相应的类变量
public boolean init()
{
this.strSql="select * from `user` where userid=";
this.strSql=this.strSql + "'" + this.userid + "'";
try
{
ResultSet rs = super.exeQuery(this.strSql);
if (rs.next())
{
this.userid=rs.getLong("userid");
this.uname=rs.getString("uname");
this.name=rs.getString("name");
this.pwd=rs.getString("pwd");
this.sex=rs.getString("sex");
this.email=rs.getString("email");
this.address=rs.getString("address");
this.tel=rs.getString("tel");
this.birth=rs.getString("birth");
this.post=rs.getString("post");
this.safequestion=rs.getString("safequestion");
this.safeanswer=rs.getString("safeanswer");
this.money=rs.getString("money");
this.createtime=rs.getString("createtime");
return true;
}
else
{
return false;
}
}
catch(Exception e)
{
System.out.println(e.toString());
return false;
}
}
//验证用户名和密码是否正确
public boolean valid()
{
this.strSql="select userid,uname,role from `user` ";
this.strSql=this.strSql + " where uname='" + this.uname + "'";
this.strSql=this.strSql + " and pwd='"+ this.pwd + "'";
System.out.println(this.strSql);
try
{
ResultSet rs = super.exeQuery(this.strSql);
if (rs.next())
{
this.userid=rs.getLong("userid");
this.uname=rs.getString("uname");
this.role = rs.getString("role");
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
return false;
}
}
//判断用户名是否存在
public boolean exist()
{
this.strSql="select * from `user` ";
this.strSql=this.strSql + " where uname='" + this.uname + "'";
try
{
ResultSet rs = super.exeQuery(this.strSql);
if (rs.next())
{
return true;
}
else
{
return false;
}
}
catch(Exception e)
{
System.out.println(e.toString());
return false;
}
}
//设置类成员变量userid的值
public void setUserid(long userid)
{
this.userid = userid;
}
//获取类成员变量userid的值
public long getUserid()
{
return this.userid;
}
//设置类成员变量uname的值
public void setUname(String uname)
{
this.uname = uname;
}
//获取类成员变量uname的值
public String getUname()
{
return this.uname;
}
//设置类成员变量name的值
public void setName(String name)
{
this.name = name;
}
//获取类成员变量name的值
public String getName()
{
return this.name;
}
//设置类成员变量pwd的值
public void setPwd(String pwd)
{
this.pwd = pwd;
}
//获取类成员变量pwd的值
public String getPwd()
{
return this.pwd;
}
//设置类成员变量sex的值
public void setSex(String sex)
{
this.sex = sex;
}
//获取类成员变量sex的值
public String getSex()
{
return this.sex;
}
//设置类成员变量Email的值
public void setEmail(String email)
{
this.email = email;
}
//获取类成员变量Email的值
public String getEmail()
{
return this.email;
}
//设置类成员变量address的值
public void setAddress(String address)
{
this.address = address;
}
//获取类成员变量address的值
public String getAddress()
{
return this.address;
}
//设置类成员变量tel的值
public void setTel(String tel)
{
this.tel = tel;
}
//获取类成员变量tel的值
public String getTel()
{
return this.tel;
}
//设置类成员变量birth的值
public void setBirth(String birth)
{
this.birth = birth;
}
//获取类成员变量birth的值
public String getBirth()
{
return this.birth;
}
//设置类成员变量post的值
public void setPost(String post)
{
this.post = post;
}
//获取类成员变量post的值
public String getPost()
{
return this.post;
}
//设置类成员变量safequestion的值
public void setSafequestion(String safequestion)
{
this.safequestion = safequestion;
}
//获取类成员变量safequestion的值
public String getSafequestion()
{
return this.safequestion;
}
//设置类成员变量safeanswer的值
public void setSafeanswer(String safeanswer)
{
this.safeanswer = safeanswer;
}
//获取类成员变量safeanswer的值
public String getSafeanswer()
{
return this.safeanswer;
}
//设置类成员变量money的值
public void setMoney(String money)
{
this.money = money;
}
//获取类成员变量money的值
public String getMoney()
{
return this.money;
}
//设置类成员变量CreateTime的值
public void setCreaTetime(String createtime)
{
this.createtime = createtime;
}
//获取类成员变量CreateTime的值
public String getCreateTime()
{
return this.createtime;
}
//设置类成员变量Role的值
public void setRole(String role)
{
this.role = role;
}
//获取类成员变量Role的值
public String getRole()
{
return this.role;
}
}
-------------------------------------------------------------------------
ExecuteDB.java
package com.bar.db;
import java.sql.*;
//这个类继承自ConnectDB类
public class ExecuteDB extends ConnectDB
{
//数据库连接对象
private Connection dbConn;
private Statement stmt;
private ResultSet rs;
//error 描述 错误信息
private String errMes;
//初始化操作
public ExecuteDB()
{
dbConn = super.getConn();
stmt = null;
rs = null;
this.errMes = super.getErrMes();
}
//执行sql 执行语句,主要是执行插入和删除的SQL语句
public boolean exeSql(String strSql)
{
boolean isSuc = false;
try
{
stmt=dbConn.createStatement();
stmt.executeUpdate(strSql);
stmt.close();
isSuc = true;
}
catch(Exception e)
{
this.errMes = this.errMes + "<br>" +e.toString();
}
return isSuc;
}
//执行sql查询语句
public ResultSet exeQuery(String strSql)
{
try
{
stmt=dbConn.createStatement();
rs =stmt.executeQuery(strSql);
}
catch(Exception e)
{
this.errMes = this.errMes + "<br>" +e.toString();
rs = null;
}
return rs;
}
//取得错误信息
public String getErrMes()
{
return errMes;
}
}
---------------------------------------------------------------------------
ConnectDB.java
package com.bar.db;
import java.sql.*;
public class ConnectDB
{
//数据库用户名
String userName="root";
//数据库密码
String userPassword="123456";
//数据库的URL,包括连接数据库所使用的编码格式
String url="jdbc:mysql://localhost:3306/chapter12?useUnicode=true&characterEncoding=gb2312";
//定义一个连接对象
Connection dbConn;
//错误信息串
String errMes;
public ConnectDB()
{
//初始化操作
errMes="";
dbConn=null;
}
//连接数据库
public Connection getConn()
{
try
{
//声明所用的类包
Class.forName("com.mysql.jdbc.Driver");
//获得数据库的连接对象
dbConn= DriverManager.getConnection(url,userName,userPassword);
}
catch(Exception e)
{
dbConn = null;
errMes=e.toString();
}
return dbConn;
}
//获取错误信息
public String getErrMes()
{
return errMes;
}
}