(오라클+자바) 데이타베이스에 데이타 올리기-04
이제 hr계정에서 lucky 계정으로 옮길것이다.
hr 계정
grant select on employees to lucky;
lucky 계정
create table emp as
select employee_id as emp_id, First_Name || ' ' || Last_Name As irum,email,phone_number as phone,
hire_date as hidate, salary as pay from hr.employees;
desc emp;
select * from emp;
desc emp;
select * from emp;
create table emp2 as
select * from emp where 0 > 5;
select * from emp2;
desc emp2;
alter table emp2
add constraint emp2_pk primary key(emp_id) ;
hr 계정
grant select on employees to lucky;
lucky 계정
create table emp as
select employee_id as emp_id, First_Name || ' ' || Last_Name As irum,email,phone_number as phone,
hire_date as hidate, salary as pay from hr.employees;
desc emp;
select * from emp;
desc emp;
select * from emp;
create table emp2 as
select * from emp where 0 > 5;
select * from emp2;
desc emp2;
alter table emp2
add constraint emp2_pk primary key(emp_id) ;
JAVA ->
package lucky;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class EmployeeProcess {
public static void main(String[] args) {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "lucky", "lucky");
stmt = con.createStatement();
//String query = "select us_id, us_pwd, us_name, us_addr, hire_date, us_level from users";
String query = ("select emp_id, irum, email, phone, hidate, pay from emp");
rs = stmt.executeQuery(query);
while(rs.next()) {
System.out.print("사번 : " + rs.getInt("emp_id") + " ");
System.out.print("급여 : " + rs.getDouble("pay") + " ");
System.out.print("이름 : " + rs.getString("irum") + " ");
System.out.print("이메일 : " + rs.getString("email") + " ");
System.out.print("폰 : " + rs.getString("phone") + " ");
System.out.print("입사일 : " + rs.getString("hidate") + "\n");
}
}catch(ClassNotFoundException e) {
e.printStackTrace();
}catch(SQLException e) {
e.printStackTrace();
}finally {
if(rs != null) {
try {rs.close();}catch(SQLException e) {e.printStackTrace();}finally {}
}
if(stmt != null) {
try {stmt.close();}catch(SQLException e) {e.printStackTrace();}finally {}
}
if(con != null) {
try {con.close();}catch(SQLException e) {e.printStackTrace();}finally {}
}
}
}
}
이렇게 뜬다
댓글
댓글 쓰기