Database Programming using JSP and MySQL Byung-Hyun Ha
Table of Contents Database Application Overview of Application Building Database Access via Telnet File System Access via FTP First JSP Programming Database Programming using JSP Discussion
Database Application Multi-tier architecture front-end back-end Networ k presentation layer business logic DB front-end back-end Networ k business logic + presentation layer DB
Our Database Application 게시판 front-end back-end Networ k business logic + presentation layer DB Web browserJSP pageMySQLInternet
ike.ie.pusan.ac.kr (linux machine) Back-End Architecture Powered by linux Internet Apache Tomcat (Application Server) JSP page (program) MySQL (DBMS) Database
Overview of Application Building Telnet + FTP + MySQL console ike.ie.pusan.ac.kr Telnet daemon Internet FTP daemon shell file system JSP page (program) Database Tomcat MySQL
Database Access via Telnet 1.Login 시작 실행 “ telnet ike.ie.pusan.ac.kr ” ID 와 password 입력 2.Password 의 수정 passwd 3.Logout exit 4. 다시 login
Database Access via Telnet 1.Database console 에 login mysql -u uXXXXX -p Password 입력 2.Database console 에서 logout quit 3.Password 의 수정 mysqladmin -u uXXXXX –p password ‘YYYYYYYY’ 4.Console 에 다시 login
Database Access via Telnet 1. 사용 가능한 database 보기 show databases; 2.Database 사용 use dXXXXX 3.Table 생성 create table test(no int, name varchar(20)); 4.Table 확인 show tables; 5.Record 입력 insert into test values(10, ‘abc’); 6. 입력된 내용 확인 select * from test;
Database Access via Telnet ike.ie.pusan.ac.kr Telnet daemon Internet FTP daemon shell file system JSP page (program) Database Tomcat MySQL 지금 한 것
File System Access via FTP 테스트 Web page 작성 1. 시작 실행 “ notepad ” 2. 다음을 입력 3. 바탕 화면에 ‘test.html’ 로 저장 Hello! HTML!
File System Access via FTP 1.Internet Explorer 실행 2. 주소 창에 다음을 입력 ftp://ike.ie.pusan.ac.kr/webapps/ 3. 파일 다른 이름으로 로그인 자신의 ike.ie.pusan.ac.kr 계정을 사용하여 로그인 4.‘test.html’ 을 Internet Explorer 에 drag & drop 5. 새로운 Internet Explorer 실행
File System Access via FTP 지금 한 것 ike.ie.pusan.ac.kr Telnet daemon Internet FTP daemon shell file system JSP page (program) Database Tomcat MySQL
File System Access via FTP 1.MySQL 을 종료함 2. 현재 경로의 내용확인 ls 3.‘test.html’ 확인 cd webapps ls
Our First JSP Programming 테스트 JSP page 작성 notepad 를 열어 다음을 입력하고, ‘test.jsp’ 로 저장 <% String str = request.getParameter("name"); if (str != null) { out.println("You have input " + str); } %> Your input?
Our First JSP Programming 1.‘test.jsp’ 를 ike 로 전송 2. 결과 확인
Our First JSP Programming 만일 오류가 있다면 ?
Database Programming using JSP ‘list.jsp’ 의 작성 <% try { String dbUrl = "jdbc:mysql://localhost/dXXXXX?user=uXXXXX&password=YYYYYY"; Connection conn = DriverManager.getConnection(dbUrl); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM test"); while (rs.next()) { int no = rs.getInt("no"); String name = rs.getString("name"); out.println(no + ", " + name + " "); } rs.close(); stmt.close(); conn.close(); } catch (Exception e) { out.println(e); } %> insert
Database Programming using JSP ‘insert.jsp’ 의 작성 <% String no = request.getParameter("no"); String name = request.getParameter("name"); if (no != null && name != null) { try { String dbUrl = "jdbc:mysql://localhost/dXXXXX?user=uXXXXX&password=YYYYYY"; Connection conn = DriverManager.getConnection(dbUrl); Statement stmt = conn.createStatement(); String query = "INSERT INTO test (no, name) VALUES (" + no + ", '" + name + "')"; stmt.execute(query); stmt.close(); conn.close(); out.println("one row inserted."); } catch (Exception e) { out.println(e); } %> list
Overview of Application Building Telnet + FTP + MySQL console ike.ie.pusan.ac.kr Telnet daemon Internet FTP daemon shell file system JSP page (program) Database Tomcat MySQL
Database Application Multi-tier architecture front-end back-end Networ k presentation layer business logic DB front-end back-end Networ k business logic + presentation layer DB
Discussion HTML vs. JSP 한글 ? 숙제의 의미 ?