Answer the question
In order to leave comments, you need to log in
How to find row id by string value in MySQL?
I want to find row id in mySQL table by string value(java). That is, for example, I have columns id, name and age. And I want to find Anya named "Anya" and find out what her id is. And if there are several An? How can I find only the first or just some one (doesn't matter)? I added LIMIT 1. Here are some options that have been tried:
id = jdbcTemplate.query("SELECT * FROM people WHERE name LIKE '%{$"+Ann+"}%'", new ResultSetExtractor<Long>() {
@Override
public Long extractData(ResultSet rs) throws SQLException,
DataAccessException {
return rs.next() ? rs.getLong("id") : null ;
}
});
id = jdbcTemplate.query("SELECT * FROM people WHERE name = 'Ann'", new ResultSetExtractor<Long>() {
@Override
public Long extractData(ResultSet rs) throws SQLException,
DataAccessException {
return rs.next() ? rs.getLong("id") : null ;
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question