连不上数据库
public class MessageImp
implements MessageInterface {
private Connection con;
private PreparedStatement stm;
//数据库的连接
public MessageImp() {
String CLASSFORNAME = "org.gjt.mm.mysql.Driver ";
String SERVANDDB =
"jdbc:mysql://localhost:3306/jspdev?useUnicode=true&characterEncoding=gb2312 ";
String USER = "root ";
String PWD = "666666 ";
Connection con;
try {
Class.forName(CLASSFORNAME);
con = DriverManager.getConnection(SERVANDDB, USER, PWD);
}
catch (Exception e) {
e.printStackTrace();
}
}
连不上,con一直为null 郁闷ing!!!!
------解决方案--------------------private Connection con;和 构造函数里的Connection con;
------解决方案--------------------把构造中的 Connection con; 删除。
建议把 org.gjt.mm.mysql.Driver 改为 com.mysql.jdbc.Driver,因为这个驱动已经过时了,不过用起来是一样的。
------解决方案--------------------错误信息都没有,让大家陪你猜谜语啊?