그냥 배우는 언어 기록하는 공간 :D

국비 학원 기록

[03/12] 로또 번호, 카드 뽑기, 기초 SQL(select, insert, delete, update), boardList, 페이징, 쿼리 생성

꾸준히_노력하기 2025. 3. 27. 00:56

[로또 번호 생성기]

// suffle(셔플) 알고리즘
int temp = ball[0];  // 0번째 값을 (임시로) 복사
ball[0] = ball[num]; // 무슨 값인지 모름
ball[num] = temp;

 


[카드 뽑기]

 

 


[기초 SQL]

- select, insert, delete, update

 


[boardList.jsp]

 

 

 

 


 

[ boardList.jsp 과제]

 

 

// 페이징 준비
int currentPage = 1;
if(request.getParameter("currentPage") != null) {
	currentPAge = Integer.parseInt(request.getParameter("currentPage"));
}    
int rowPerPage = 10;
int startRow = (currentPage - 1) * rowPerPage;


// 1) 드라이버 로딩 | 로딩: 메모리 위에 강제로 올리는 것
Class.forName("com.mysql.cj.jdbc.Driver"); // 대문자로 시작했으니까 static -> 명령어 X 

// 2) 접속(mysql 주소, mysql 계정, mysql 암호)
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db0312", "root", "java1234");

// 3-1) 접속한 DB에 전달할 SQL쿼리 준비 -> PreparedStatement 데이터 타입 저장
PreparedStatement stmt = conn.prepareStatement("select from order by limit");

// 3-2) 쿼리 완성

// 4) PreparedStatement 데이터 타입에 저장된 SQL쿼리 실행 명령 후 쿼리 결과 값 반환 받음
ResultSet rs = stmt.executeQuery(); // ResultSet -> 인덱스가 없는 배열 | 커스로 출력?함

 

<!-- 페이징 -->
<a href="/web0312db/boardList.jsp?currentPage=<%=currentPage-1%>">[이전]</a>
<a href="/web0312db/boardList.jsp?currentPage=<%=currentPage+1%>">[다음]</a>