Repository navigation
Expand file tree
/
Copy pathQuestionDao.java
More file actions
43 lines (35 loc) · 1.49 KB
/
Copy pathQuestionDao.java
File metadata and controls
43 lines (35 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package next.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import core.jdbc.JdbcTemplate;
import core.jdbc.RowMapper;
import next.model.Question;
public class QuestionDao {
public Question findById(Long questionId) {
// TODO Auto-generated method stub
JdbcTemplate jdbcTemplate = new JdbcTemplate();
String sql = "SELECT questionId, writer, title, contents, createdDate, countOfAnswer FROM QUESTIONS WHERE questionId = ?";
RowMapper<Question> rm = new RowMapper<Question>() {
@Override
public Question mapRow(ResultSet rs) throws SQLException {
// TODO Auto-generated method stub
return new Question(rs.getLong("questionId"), rs.getString("writer"), rs.getString("title"), rs.getString("contents"), rs.getDate("createdDate"), rs.getInt("countOfAnswer"));
}
};
return jdbcTemplate.queryForObject(sql, rm, questionId);
}
public List<Question> findAll() {
// TODO Auto-generated method stub
JdbcTemplate jdbcTemplate = new JdbcTemplate();
String sql = "SELECT questionId, writer, title, contents, createdDate, countOfAnswer FROM QUESTIONS";
RowMapper<Question> rm = new RowMapper<Question>() {
@Override
public Question mapRow(ResultSet rs) throws SQLException {
// TODO Auto-generated method stub
return new Question(rs.getLong("questionId"), rs.getString("writer"), rs.getString("title"), rs.getString("contents"), rs.getDate("createdDate"), rs.getInt("countOfAnswer"));
}
};
return jdbcTemplate.query(sql, rm);
}
}