Home > Enterprise >  How others can connect to my postgreSQL server so my login platform can work?
How others can connect to my postgreSQL server so my login platform can work?

Time:11-11

I am working on a hotel management system project and I want to make a login platform, which takes data from an AWS RDS PostgreSQL server that I have created. The problem is that people from other networks who I sent the .exe file of this project can't login but I can.

I have created the tables I wanted in pgAdmin4 and also I have installed the Postgres drivers in my project libraries.

Here is my connection class, where URL, user and pass are defined in the project:

public class ServerConnection {
    
      static Connection getConnection() {
          Connection connection = null;
          try{
              connection = DriverManager.getConnection(url, user, pass);
            if(connection != null) {
                System.out.println("Connected");
            }
            else {
                System.out.println("Failed");
            }
          } catch (SQLException e) {
            e.printStackTrace();
          }
         return connection;
    }
}

And below is the login method:

public void performLogin() {
        PreparedStatement st;
        ResultSet rs;
        String user = username.getText();
        String pass = String.valueOf(password.getPassword());
        String query = "SELECT * FROM ADMINS WHERE username=? AND passw=?";
        
        try {
            st = serverConnection.getConnection().prepareStatement(query);
            st.setString(1, user);
            st.setString(2, pass);
            
            rs = st.executeQuery();
            
            if(rs.next()) {
                hotelFrame2 hf2 = new hotelFrame2();
                this.dispose();
            }
            else {
                JOptionPane.showMessageDialog(null, "Invalid Username / Password","LoginError",2);
            }
            
        } catch (SQLException e1) {
            e1.printStackTrace();
        }   
    }

How can I fix it?

CodePudding user response:

The problem is that people from other networks who I sent the .exe file of this project can't login but I can.

It seems you are authorizing only your computer(IP) to connect to the RDS database, to solve your issue you have to open the flow to the other people by changing the security group.

By the way, using JDBC with AWS really hurt me, it is really an old way, it's better to look at JPA, Hibernate, or even some other AWS services.

  • Related