Answer the question
In order to leave comments, you need to log in
How to save data from html page in android application?
In general, there is a table ( studydep.miigaik.ru/index.php) with the university schedule.
I parse it with jsoup and I can get the rows/columns.
How do I store this data from a table?
The idea is this - the user selects a faculty, course, group, the application parses this table and displays it in fragments by day of the couple.
If this is done using a database, then which one and how will it be most convenient to implement it?
Answer the question
In order to leave comments, you need to log in
ORM+JPA+Hibernate+DAO.
We connect to the base, then we send a request to it, then we process the response.
We implement a class that stores an element in the database as an object:
@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;
}
The parser application lives until the first layout change.
Sew Tight Faculty-Course-Group
Let the person choose one or more of them.
store the current parsing result as you like = cache. At least a file. Better parsing results. but if the parsing
is fast, you can also fold the html.
on the update button, you request and parse the page. Dismantled successfully - replaced the cache.
notified the main activity that the data has been updated.
It makes no sense to lick such a craft and write academically correctly. Probably put it on play too.
Well, if you want to write humanly, then get the data from your API.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question