Connect to sql-database using Java

I have no issue connecting to the database using PHP, which is great, but i would like to have a desktop app writen in java displaying my database values.
So this is the Side (PHP): http://leoswebserver.epizy.com/index.php
The Java code i tried:
import java.sql.*;

public class index {
public static void main(String args) {
try {
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
System.out.println(“1”);
java.sql.Connection con = DriverManager.getConnection(“jdbc:mysql://sql303.epizy.com:3306/epiz_237047xx_people”,“xxx”,“xxx”);
System.out.println(“2”);
con.setReadOnly(true);
java.sql.Statement stmt = con.createStatement();
System.out.println(“3”);
ResultSet rs = stmt.executeQuery(“SELECT * FROM people”);
System.out.println(“4”);
while(rs.next()) {
System.out.println(rs.getInt(1)+ " " +rs.getString(2));
}
System.out.println(“5”);
rs.close();
stmt.close();
con.close();

	}catch(Exception e) {
		System.out.println("Fehler: " + e);
	}
	System.out.println("Yay");
}

}

(The password/user are replaced but in they are correct because the values work in php)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class sql_connecc {
public static void main(String args) {

    // Create a variable for the connection string.
    String connectionUrl = "jdbc:sqlserver://sql303.epizy.com:3306;databaseName=epiz_237047xx_people;user=xxx;password=xxx";
    try {
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		System.out.println("ya");
	} catch (ClassNotFoundException e1) {
		e1.printStackTrace();
	}
	
    try {
    	Connection con = DriverManager.getConnection(connectionUrl); 
    	Statement stmt = con.createStatement();
        String SQL = "SELECT * FROM people";
        ResultSet rs = stmt.executeQuery(SQL);

        // Iterate through the data in the result set and display it.
        while (rs.next()) {
            System.out.println(rs.getString(1) + " " + rs.getString(2));
        }
    }
    // Handle any errors that may have occurred.
    catch (SQLException e) {
        e.printStackTrace();
    }
}

}

My Database:

Forgot the error message:
com.microsoft.sqlserver.jdbc.SQLServerException: Fehler beim Herstellen der TCP/IP-Verbindung mit dem Host ‘sql303.epizy.com’, Port 3306. Fehler: ‘connect timed out. Überprüfen Sie die Verbindungseigenschaften, und stellen Sie sicher, dass eine SQL Server-Instanz auf dem Host ausgeführt wird, die TCP/IP-Verbindungen am Port annimmt. Überprüfen Sie außerdem, dass die TCP-Verbindungen mit dem Port nicht von einer Firewall blockiert werden.’.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at sql_connecc.main(sql_connecc.java:20)

Sorry that its german

Hi

https://infinityfree.net/support/connecting-to-mysql-from-elsewhere/

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.