여기서는 while를 써야 한다.
package ex1;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ex2 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String url = "jdbc:oracle:thin:@localhost:1521/xe";
String sql = "SELECT * FROM NOTICE";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(url,"scott","tiger");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
int id = rs.getInt("ID");
String title = rs.getString("TITLE");
String writerId = rs.getString("WRITER_ID");
Date regDate = rs.getDate("REGDATE");
String content = rs.getString("CONTENT");
int hit = rs.getInt("HIT");
System.out.println(id + title + writerId + regDate + content + hit);
}
st.close();
con.close();
}
}
'JAVA Programming > JDBC' 카테고리의 다른 글
[하루 계획] 2022-04-05 (0) | 2022.04.05 |
---|---|
[8] JDBC 트랜잭션 처리 (0) | 2020.08.05 |
[4] 테이블 생성 및 JDBC 코드 접속하기 (0) | 2020.08.04 |
[3] JDBC 기본 코드의 이해 (0) | 2020.08.04 |
[2] DBMS 와 JDBC Driver 준비하기 (0) | 2020.08.04 |