Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
How to make the user see his own data after registration?

For example, I've got MySQL table with all users data

enter image description here

How to make after user sign in, he sees his own username?

I've tried this:

con = DriverManager.getConnection(url, user, password);
stmt = con.createStatement();
rs = stmt.executeQuery(query);

while (rs.next()) {
  String name = rs.getString(1);
  System.out.println("username : " + name);
}

But it just shows all usernames in MySQL table.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Your query does not filter the rows of the table.
Use a WHERE clause:

String query = "select username from users where username = ?";
stmt.setString(1, user); 
rs = stmt.executeQuery(query);
if (rs.next()) {
    String name = rs.getString(1);
    System.out.println("username : " + name);
} else {
    System.out.println("No user : " + user);
}

The ? placeholder will be replaced by the value of the variable user properly quoted.

over 4 years ago · Santiago Trujillo Denunciar

0

String query = "select username from users";

to

String query = "select username from users where username = '"+user+"' ";

To avoid sql injections, it is advisable to use a PreparedStament. Check this link for more details: https://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda