Can't Make Jdbc Connection to MySQL (Using Java, Intellij, and Linux)

Can't make JDBC connection to MySQL (using Java, IntelliJ, and Linux)

From your connection string, this database should be on the local machine. Can you try running this command to ensure the socket is open for connections?

telnet 127.0.0.1 3306

and ensure that it connects? You may not have configured your mysql instance to listen for connections from this machine or on this interface address. If the connection fails, you need to modify your mysql config, for example:

http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

Use JDBC/Mysql Connector in intellij idea

You have to add 'mysql:mysql-connector-java:5.1.40' from maven or add it as java library as shown:

Sample Image

Java JDBC connection refused

I have managed to solve the issue on my own. I have changed my connection code to something a little different. And it seems to not error out at all! My new MySQL connection code:

MysqlDataSource ds = new MysqlDataSource();
ds.setDatabaseName("DATABASE");
ds.setUser("USERNAME");
ds.setPassword("USER PASSWORD");
ds.setServerName("localhost");
ds.setPort(3306);
connection = ds.getConnection();


Related Topics



Leave a reply



Submit