My SQL 비번: admin1234
집에 노트북에서도 설치하셈
//JDBC(Java data base connectivity)
프로그램 순서 7단계
01단계 :드라이버 로딩(mysql 드라이버 로딩) : 복합기(하드웨어)
02단계 :Connection객체로 DB연결
1)ip 2)port번호 3)db접속id 4)db접속비번 5)db명(sid,service name)
03단계 :Query실행을 위한 준비
( statement 또는 PreparedStatement객체생성)
04단계 :Query실행
05단계 :Query실행결과 사용
(insert,update,delete의 경우 생략 가능단계)
06단계 :statement 또는 PreparedStatement객체 종료(close())
07단계 :DB연결(Connection 객체) 종료(close())
왜? 필요없을땐 끊어야지!
create table tb_member(
m_id VARCHAR(10) NOT NULL PRIMARY KEY,
m_pw VARCHAR(10) NOT NULL,
m_level VARCHAR(10) NOT NULL,
m_name VARCHAR(20) NOT NULL,
m_email VARCHAR(80)
)DEFAULT CHARSET=euckr;
insert into tb_member values('id001','pw001','관리자','홍01','test01');
insert into tb_member values('id002','pw002','판매자','홍02','test02');
insert into tb_member values('id003','pw003','판매자','홍03','test03');
insert into tb_member values('id004','pw004','구매자','홍04','test04');
insert into tb_member values('id005','pw005','구매자','홍05','test05');
create table tb_goods(
g_code VARCHAR(10) NOT NULL PRIMARY KEY,
g_name VARCHAR(10) NOT NULL,
g_cate VARCHAR(10) NOT NULL,
g_price VARCHAR(20) NOT NULL,
g_desc VARCHAR(80)
)DEFAULT CHARSET=euckr;
create table tb_goods(
g_code VARCHAR(20) NOT NULL PRIMARY KEY,
m_id VARCHAR(20) NOT NULL,
g_name VARCHAR(20) NOT NULL,
g_cate VARCHAR(20) NOT NULL,
g_price VARCHAR(20) NOT NULL,
g_color VARCHAR(20) NOT NULL,
g_size VARCHAR(20) NOT NULL,
g_date VARCHAR(20) NOT NULL,
g_desc VARCHAR(80)
)DEFAULT CHARSET=euckr;
INSERT INTO tb_goods VALUES ('goods_1', 'id001', '1', '1', '1', '1', '1', now(), '1');
INSERT INTO tb_goods VALUES ('goods_2', 'id002', '2', '2', '2', '2', '2', now(), '2');
select substring(g_code,7) from tb_goods;
select max(CAST(substring(g_code,7) AS DECIMAL)) from tb_goods;
select max(CAST(substring(g_code,7) AS DECIMAL)) as maxcol from tb_goods;
//회원과 상품 join 예
select tb_member.*, tb_goods.* from tb_member inner join tb_goods on tb_member.m_id = tb_goods.m_id
and DATE_FORMAT(g_date,'%Y-%m-%d') between '2021-04-01' and '2021-04-05' order by g_date
//오라클용
create table oracle_goods(
g_code VARCHAR2(20) NOT NULL PRIMARY KEY,
ora_id VARCHAR2(20) NOT NULL,
g_name VARCHAR2(20) NOT NULL,
g_cate VARCHAR2(20) NOT NULL,
g_price VARCHAR2(20) NOT NULL,
g_color VARCHAR2(20) NOT NULL,
g_size VARCHAR2(20) NOT NULL,
g_date VARCHAR2(20) NOT NULL,
g_desc VARCHAR2(80)
)
INSERT INTO oracle_goods VALUES ('goods_1', 'id001', '1', '1', '1', '1', '1', sysdate , '1');
INSERT INTO oracle_goods VALUES ('goods_2', 'id002', '2', '2', '2', '2', '2', sysdate , '2');
INSERT INTO oracle_goods VALUES ('goods_3', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_4', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_5', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_6', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_7', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_8', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_9', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_10', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_11', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_12', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_13', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
INSERT INTO oracle_goods VALUES ('goods_14', 'id003', '3', '3', '3', '3', '3', sysdate , '3');
select substr(g_code,7) from oracle_goods;
select max(substr(g_code,7)) from oracle_goods;
select max(to_number(substr(g_code,7))) from oracle_goods;
'기록(노트)' 카테고리의 다른 글
자바스크립트 함수 (0) | 2023.04.03 |
---|---|
자바스크립트 var,let.const의 차이 변수선언 및 할당/실습2 (0) | 2023.03.30 |
session.setAttribute("",""); 하는 역할이 뭐야?/판매자,구매자 실습(jsp, 로그인화면) (0) | 2023.03.28 |
실습)jsp와java연결_화면에서 두수입력받아_계산결과를 화면에출력 (0) | 2023.03.27 |
JavaScript 배열 및 arr[arr.length] 이해2/객체선언 (0) | 2023.03.24 |