CLI(Command Line Interface or Character User Interface 환경=콘솔모드) : 자원을 적게 잡아 먹으면서 안정적이고 빠르다. 게다가 원격으로 작업할 때 웬만한 네트워크 환경에서도 안정적으로 작업할 수 있으며 사용되는 데이터 양 역시 압도적으로 적다. 서버 쪽에서는 작업 자동화[1]와 원격 작업이 필요한 경우가 많은데 CLI는 이 분야에서 압도적인 효율을 보여준다.
JDBC 드라이버들은 자바 프로그램의 요청을 DBMS가 이해할 수 있는 프로토콜로 변환해주는 클라이언트 사이드어댑터이다. (서버가 아닌 클라이언트 머신에 설치)
자바 애플리케이션이 데이터베이스 연결이 필요할 때DriverManager.getConnection()메소드들 가운데 하나를 사용하여 JDBC 연결을 만들게 된다. 사용된 URL은 특정 데이터베이스와 JDBC 드라이버에 의존한다. "jdbc:" 프로토콜로 무조건 시작하지만 나머지 부분은 특정 벤더에 따라 다르다.
Connection conn = DriverManager.getConnection(
"jdbc:somejdbcvendor:other data needed by some jdbc vendor",
"myLogin",
"myPassword" );
try { /* you use the connection here */
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable e) { /* Propagate the original exception
instead of this one that you want just logged */ logger.warn("Could not close JDBC Connection",e); }
}
try (Connection conn = DriverManager.getConnection(
"jdbc:somejdbcvendor:other data needed by some jdbc vendor",
"myLogin",
"myPassword" ) ) {
/* you use the connection here */
} // the VM will take care of closing the connection
연결이 확립되면 다음과 같은 문을 작성할 수 있다.
try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate( "INSERT INTO MyTable( name ) VALUES ( 'my name' ) " );
}
create table 테이블명(
컬럼명 타입 옵션(선택사항),
컬럼명 타입,
...
)
[타입] 기본적인 것만
문자 varchar2
숫자 number
날짜 date
[컬럼 옵션]
primary key - 하나의 컬럼만 적용가능(중복값 X), not null이 기본 세팅 되어있음.
not null - null 값을 허용하지 않는다=컬럼 필수
default ' '/0 - 기본값 설정, not null 설정이 필요없단 뜻
check - 조건 설정
unique - 중복값X(외적으로 보이지 않음, pk는 보임,잘안씀)ㅌ
foreign key - 외부에서 참조하는 값(외부와 연결된다)
[사용 예시]
create table test
(
num number primary key,
memo varchar2(4000) nuique,
name varchar2(100) default 'guest',
age number check(age>0 and age<150), - if문과 동일
reg date default sysdate(사용자 설정시간)
);
+drop table 테이블명; table 삭제
+컨트롤+엔터 : 세미콜론 부분 실행
+desc 테이블명; table 정보 확인
명심. varchar2는 반드시 크기를 지정해줘야 한다. 안 그러면 에러뜸. ex) varchar(44); 이렇게
오류 보고 - ORA-00906: 누락된 좌괄호 00906. 00000 - "missing left parenthesis"