rs.next() 로 값이 있는 모든 컬럼을 출력하기
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);
if(rs.next()) {
int id = rs.getInt("ID");
String title = rs.getString("TITLE");
String writerId = rs.getString("WRITER_ID");
String content = rs.getString("CONTENT");
Date regDate = rs.getDate("REGDATE");
int hit = rs.getInt("HIT");
System.out.println(id + title + writerId + regDate + content + hit);
st.close();
con.close();
}
}
}
'JAVA Programming > JDBC 문제' 카테고리의 다른 글
[7] JDBC 문제 풀기 , 조건문이용하면안되고 SQL 로 필터링 한다. (0) | 2020.08.05 |
---|