数据库连接失败 - Netbeans 8.1 - MySQL

时间:2016-06-30 00:50:53

标签: java mysql netbeans phpmyadmin

Hello其他程序员,

编程方面还很新 - 连接数据库和东西。

我会用我的代码和我遇到的问题发布6张图片。我不知道我做错了......

我可以使用数据库连接Netbeans,但显然如果我运行应用程序,则会出错。

我希望有人可以帮助我...

我使用端口2121配置了MySQL数据库 (密码为root,用户名为root) As you can see - port 2121

在phpMyadmin中一切正常,所以数据库是实时的。 (专注于VivesBike) phpMyadmin

在Netbeans的" services" connection works

我的连接经理 connectionmanager

最后但并非最不重要...... 如你所见,一切都正确填写...... db.properties

但我仍然设法得到这个:

error

如果我需要在这里写代码..没问题。 或者我可以将项目发送给某人帮助我,但我似乎无法找到问题。

(对不起,如果这看起来像一个愚蠢的问题)

编辑:

这是DBproperties类的代码:

package database;

import exception.DatabaseException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


public class DbProperties {
private static String url;
private static String user;
private static String password;
private static String driver;

private DbProperties() throws DatabaseException{
    Properties dbProperties = new Properties();
    try(InputStream in = this.getClass().getResourceAsStream("properties/DB.properties")){
        //File tmp = File.createTempFile(String.valueOf(in.hashCode()), "temp");
        //tmp.deleteOnExit();
        //try(FileInputStream fin = new FileInputStream(tmp)){
        dbProperties.load(in);
        url = dbProperties.getProperty("url");
        user = dbProperties.getProperty("user");
        password = dbProperties.getProperty("password");
        driver = dbProperties.getProperty("driver");

        }catch (IOException ex) {
            System.out.println(ex.getMessage());
            throw new DatabaseException("File (DB.properties) not found: "+ex);
        }
   // }catch (IOException ex){
     //   throw new DatabaseException("File (DB.properties) not found: "+ex);
    //}
}

public static String getUrl() throws DatabaseException{
    if(url == null){
        DbProperties dbProp = new DbProperties();
    }
    return url;
}

public static String getUser() throws DatabaseException{
    if(user == null){
        DbProperties dbProp = new DbProperties();
    }
    return user;
}

public static String getPassword() throws DatabaseException{
    if(password == null){
        DbProperties dbProp = new DbProperties();
    }
    return password;
}

public static String getDriver() throws DatabaseException{
    if(driver == null){
        DbProperties dbProp = new DbProperties();
    }
    return driver;
}

}

编辑2:

如果驱动程序出现问题,我会在这里看到...

这是构建的结果 enter image description here

(我希望这是对你说的)

编辑3:

enter image description here

enter image description here

亲切的问候, 迪伦

0 个答案:

没有答案