I have some issue when trying to make an election application (Java and Eclipse Luna IDE) using my laptop as server and other as client. I'm also using phpMyAdmin database from XAMPP.
It's working when I use localhost and 127.0.0.1 ip as the address.
connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/db", "root", "")
and
connection = DriverManager.getConnection("jdbc:mysql://localhost/db", "root", "")
The problem is when I access this server still using my laptop, but change the address to my dynamic WI-FI IP address, it caught on errors.
connection = DriverManager.getConnection("jdbc:mysql://192.168.1.11:3306/db", "root", "")
The errors I've got is Class File editor--source not found just like these
MysqlIO.class Connectionlmpl.class
Both of those errors require me to select the location of mysql-connector-java-5.1.44.jar
, but I've already download and attach the file into package (like this) and it keeps give me those errors.
I've already googled for editing my.cnf
files to delete the bind-address, but in my case I can't found my.cnf
file, only my.ini
file that exist, so I only edit my.ini
file by deleting the bind-address code.
Could somebody help me with this problems? I cannot find out the solution,
I've just tried to test the connection using this code
String url = "jdbc:mysql://192.168.1.11:3306/db";
String username = "root";
String password = "";
System.out.println("Connecting database...");
try (Connection connection = DriverManager.getConnection(url, username, password)) {
System.out.println("Database connected!");
} catch (SQLException e) {
throw new IllegalStateException("Cannot connect the database!", e);
}
The result is
> Connecting database...
Exception in thread "main" java.lang.IllegalStateException: Cannot connect the database!
at election.ElectionApp.main(ElectionApp.java:251)
Caused by: java.sql.SQLException: null, message from server: "Host 'MyComputer.local' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1040)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2191)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly (ConnectionImpl.java:2222)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Election.ElectionApp.main(ElectionApp.java:248)