Android
- 2 ответа
- 0 вопросов
2
Вклад в тег
@Entity
@Table(name = "univer")//название таблицы в бд
public class UniverDataSet {
@Column(name="course")//название колонки в базе
private String course;
@Column(name="group")
private String group;
public UniverDataSet(String group, String course) {
this.course = course;
this.group = group;
}
//...getters
}
public class UniverDAO {
private Executor executor;
//...
public String getTimeTable(long id) throws SQLException {
PreparedStatement stmt = executor.execQuery(
"select * from users where id = '" + id + "'",
resultSet -> {
resultSet.next();
return resultSet.getString(1);
}
);
}
}
class Executor {
UsersDAO dao;
//...
public <T> T execQuery(String query, ResultHandler<T> handler) throws SQLException {
PreparedStatement stmt = connection.preparedStatement(query);
ResultSet resultSet = stmt.execute();
T value = handler.handle(resultSet);
resultSet.close();
stmt.close();
return value;
}
}
interface ResultHandler {
void handle(ResultSet resultSet) throws SQLException;
}