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: