java 程序连不上mysql数据库了

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
/**
* JDBC工具类
*
* @author Administrator
*
*/
public class JDBCUtils {
private static Properties props = new Properties();
// 这里的语句都只执行一次,我们让它在JdbcUtils这个类被加载时执行!
static {
try {
// 获取类路径下的资源
InputStream in = JDBCUtils.class
.getResourceAsStream("dbconfig.properties");
// 加载配置文件
props.load(in);
/*
* 注册驱动类
*/
Class.forName(props.getProperty("driverClassName"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 获取连接对象
*
* @return
*/
public static Connection getConnection() {
try {
/*
* 3. 获取连接对象
*/
Connection con = DriverManager.getConnection(
props.getProperty("url"), props.getProperty("username"),
props.getProperty("password"));
return con;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

这个问题,我有经验。程序没有错的情况下。
先停止mysql服务,然后打开命令行。输入mysqld_safe --skip-grant-tables
然后输入 mysql -u root
然后修改密码update user set Password = PASSWORD('新密码') where User ='root';
当然,密码也可以不改
然后flus privileges接着quit退出
然后重启mysql。
搞定追问

你的这个答案我在网上看过了,没用

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答