title: Unable to connect to mysql server because of "java.sql.SQLNonTransientConnectionException: Could not create connection to database server"
body: <p>Here is the code which i use to connect to the server:</p>
  <pre><code>String records = &quot;&quot;,error=&quot;&quot;;
          void connectToDatabase() {
              try {
                  String ip = &quot;&quot;;//mysql server ip(removed due to privacy reasons)
                  Class.forName(&quot;com.mysql.cj.jdbc.Driver&quot;).newInstance();
                  Connection connection = DriverManager.getConnection(&quot;jdbc:mysql://&quot; + ip +&quot;:3306/androiddb?user=andro&amp;password=andro&quot;);
                  Statement statement = connection.createStatement();
                  ResultSet resultSet = statement.executeQuery(&quot;SELECT * FROM mainTable&quot;);
                  while (resultSet.next()) {
                      records += resultSet.getString(1) + &quot; &quot; + resultSet.getString(2) + &quot;\n&quot;;
                  }
                  System.out.println(records);
              } catch (Exception e) {
                  error = e.toString();
                  System.out.println(error);
              }
          }
  </code></pre>
  <p>Exception i get:</p>
  <pre><code>java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
  </code></pre>
  <p>my.ini file:</p>
  <pre><code>[mysqld]
  basedir=C:\\Program Files\\MySQL\\MySQL Server 8.0
  datadir=C:\\Program Files\\MySQL\\MySQL Server 8.0\\data
  bind-address = *mysql server ip*
  </code></pre>
  <p>I use mysql server 8.0.24 and jdbc 8.0.24</p>
  <p>UPD: I don't know why but it started to work after i installed jdbc 5.0.41</p>