조회수가 10이상인 게시물만 출력되게 하시오
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";
// SQL에다가 조건절 WHERE 조건을 넣을수 있다. SQL
String sql = "SELECT * FROM NOTICE where HIT > 10";
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 문제' 카테고리의 다른 글
[5] JDBC 문제 풀기 (0) | 2020.08.04 |
---|