Home > Net >  how to get the distinct values from a column using JDBC?
how to get the distinct values from a column using JDBC?

Time:03-04

I am trying to retrive the unique values from salary column from the database using JDBC. a little help would be enough. thank you

CodePudding user response:

Connection connection = DriverManager.getConnection(DB_URL,DB_USER,DB_PASSWD);

Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery("SELECT salary FROM table_name");

CodePudding user response:

This question is possibly duplicated, but there you go:

jdbcTemplate.queryForList("SELECT DISTINCT salary from DATATABLE", Integer.class);

Second argument of this method should match the type of the salary column (I assumed it was Integer but I might be wrong).

  • Related