我使用intellij 15进行项目,所以当我试图连接到数据库时,我得到了这个错误
没有为jdbc:mysql://localhost:3306/egov找到合适的驱动程序
这是我的数据源文件
public class DataSource {
private String url;
private String login;
private String password;
private Connection connection;
private Properties properties;
private static DataSource instance;
private DataSource() {
try {
properties = new Properties();
properties.load(new FileInputStream(new File("configuration.properties")));
url = properties.getProperty("url");
login = properties.getProperty("login");
password = properties.getProperty("password");
connection = DriverManager.getConnection(url, login, password);
} catch (SQLException | IOException ex) {
System.out.println(ex.getMessage());
}
}
public Connection getConnection() {
return connection;
}
public static DataSource getInstance() {
if (instance == null) {
instance = new DataSource();
}
return instance;
}
}这是configuration.properties文件
url=jdbc:mysql://localhost:3306/egov
login=root
password=此外,我还添加了jar文件mysql-连接器-java,任何人都知道如何解决这个问题。
发布于 2016-03-11 21:10:17
您需要通过IDEA GUI加载db驱动程序文件。转到“视图”菜单,然后从“工具窗口”子菜单中选择“数据库”。在“数据库”窗口中,单击工具栏顶部的“扳手”图标,打开“数据源和驱动程序”窗口。如果您没有项目数据源下面列出的MySQL数据源,请单击左上角的+按钮来添加它,否则只需单击项目数据源下的"MySQL“行即可。查看窗口底部附近有一个链接,上面写着“下载丢失的驱动程序文件”,然后单击它将必要的驱动程序安装到IDEA中。
发布于 2016-03-11 21:15:12
阿明·哈鲍伊你试过这个吗?
login = properties.getProperty("login");
password = properties.getProperty("password");
Class.forName("com.mysql.jdbc.Driver");// include this line in your code.
connection = DriverManager.getConnection(url, login, password);
} catch (SQLException | IOException ex) {https://stackoverflow.com/questions/35949808
复制相似问题