Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!