create table login( midx int(8) not null auto_increment, mid varchar(30) not null, mpass varchar(80) not null, //MD5 16진수로 받을거임 primary key(midx), unique key(mid) );
// test위해 data 미리 하나 만들어둠 (비번 1234) insert into login values ('0','apink','81dc9bdb52d04dc2036dbd8313ed055');
🔽
spring 미리..
WEB-INF 폴더에 classes 폴더 생성 -> db.properties 파일 생성
==> 이름 고정임 내맘대로 X !
db.properties 에는 ;(세미콜론) X , 주석 작성시 #~
#properties 는 window에서 사용하는 환경설정에 .ini 파일과 동일한 형태의 파일
🔽 db.properties 파일 => db접속 정보 입력
driver = com.mysql.cj.jdbc.Driver
url = jdbc:mysql://localhost:3306/cms
user = hana
password = hana1234
select_db = select * from login order by midx desc
//이거의 장점 : ddl 이 여기에 모임
//createStatement 사용 불가
dbcon.java -> class java파일
//database 연결 + properties 활용
public class dbcon {
//classes에 있는 properties 파일을 사용하는 라이브러리
Properties pp = new Properties();
String resource = "db.properties"; //로드할 properties 파일명
public Connection db() throws Exception{
//classes 안에 있는 properties를 로드하여 모든 문자 내용을 저장시킴
this.pp.load(this.getClass().getClassLoader().getResourceAsStream(resource));
Class.forName(this.pp.getProperty("driver"));
Connection con = DriverManager.getConnection(this.pp.getProperty("url"),this.pp.getProperty("user"),this.pp.getProperty("password"));
return con;
}
}