728x90
row 데이터 전체 조회 및 반환 코드
내부 쿼리문
package com.kh.test.model.TestDao;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import com.kh.test.model.Test;
public class TestDao {
public List<Test> selectList() {
List<Test> list = null;
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
Class.forName("Oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.10.3:1521:xe","kh","kh");
String query = "SELECT * FROM TEST";
stmt = conn.createStatement();
rset = stmt.executeQuery(query);
if(rset.next()) {
int seq = rset.getInt("SEQ");
String writer = rset.getString("WRITER");
String title = rset.getString("TITLE");
String content = rset.getString("CONTENT");
Date regDate = rset.getDate("DATE");
list.add(new Test(seq, writer, title, content,regDate));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
rset.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
}
728x90
반응형
'small steps > 1일 1코딩 - 코딩을 내 몸처럼' 카테고리의 다른 글
[1일1코딩][[SQL-Oracle] 이중 조인 + 인라인뷰 서브쿼리 + RNUM (0) | 2022.05.21 |
---|---|
[1일1코딩][CSS] 후손 선택자 & flex, justify-content: space-between (0) | 2022.05.20 |
[1일1코딩][Java-SQL] 전체 조회 model.vo (0) | 2022.05.18 |
[1일1코딩][Web] web.xml 배포서술자 (0) | 2022.05.16 |
[1일1코딩] (0) | 2022.05.15 |