1 / 22

Database Programming using JSP and MySQL

Database Programming using JSP and MySQL. 2003.4.13 Byung-Hyun Ha bhha@pusan.ac.kr. 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.

hisoki
Télécharger la présentation

Database Programming using JSP and MySQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Database Programmingusing JSP and MySQL 2003.4.13 Byung-Hyun Ha bhha@pusan.ac.kr

  2. 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

  3. Database Application • Multi-tier architecture back-end front-end Network business logic + presentation layer DB back-end front-end Network presentation layer business logic DB

  4. Our Database Application • 게시판 back-end front-end Network business logic + presentation layer DB Web browser Internet JSP page MySQL

  5. Back-End Architecture • Powered by linux ike.ie.pusan.ac.kr (linux machine) Apache Tomcat (Application Server) MySQL (DBMS) Internet JSP page (program) Database

  6. Overview of Application Building • Telnet + FTP + MySQL console ike.ie.pusan.ac.kr Telnet daemon shell MySQL Database Internet file system Tomcat FTP daemon JSP page (program)

  7. Database Access via Telnet • Login • 시작  실행  “telnet ike.ie.pusan.ac.kr” • ID와 password 입력 • Password의 수정 • passwd • Logout • exit • 다시 login

  8. Database Access via Telnet • Database console에 login • mysql -u uXXXXX -p • Password 입력 • Database console에서 logout • quit • Password의 수정 • mysqladmin -u uXXXXX –p password ‘YYYYYYYY’ • Console에 다시 login

  9. Database Access via Telnet • 사용 가능한 database 보기 • show databases; • Database 사용 • use dXXXXX • Table 생성 • create table test(no int, name varchar(20)); • Table 확인 • show tables; • Record 입력 • insert into test values(10, ‘abc’); • 입력된 내용 확인 • select * from test;

  10. Database Access via Telnet • 지금 한 것 ike.ie.pusan.ac.kr Telnet daemon shell MySQL Database Internet file system Tomcat FTP daemon JSP page (program)

  11. File System Access via FTP • 테스트 Web page 작성 • 시작  실행  “notepad” • 다음을 입력 • 바탕 화면에 ‘test.html’로 저장 <html> <body> <h1>Hello! HTML!</h1> </body> </html>

  12. File System Access via FTP • Internet Explorer 실행 • 주소 창에 다음을 입력 • ftp://ike.ie.pusan.ac.kr/webapps/ • 파일  다른 이름으로 로그인 • 자신의 ike.ie.pusan.ac.kr 계정을 사용하여 로그인 • ‘test.html’을 Internet Explorer에 drag & drop • 새로운 Internet Explorer 실행 • http://ike.ie.pusan.ac.kr:8080/uXXXXX/test.html

  13. File System Access via FTP • 지금 한 것 ike.ie.pusan.ac.kr Telnet daemon shell MySQL Database Internet file system Tomcat FTP daemon JSP page (program)

  14. File System Access via FTP • MySQL을 종료함 • 현재 경로의 내용확인 • ls • ‘test.html’ 확인 • cd webapps • ls

  15. Our First JSP Programming • 테스트 JSP page 작성 • notepad를 열어 다음을 입력하고, ‘test.jsp’로 저장 <html> <body> <h1><%= "Hello, JSP! " %></h1> <% String str = request.getParameter("name"); if (str != null) { out.println("You have input " + str); } %> <hr/> <form name="form1" method="post" action="test.jsp"> Your input? <input type="text" name="name" /> <input type="submit" value="OK" /> </form> </body> </html>

  16. Our First JSP Programming • ‘test.jsp’를 ike로 전송 • 결과 확인

  17. Our First JSP Programming • 만일 오류가 있다면?

  18. Database Programming using JSP • ‘list.jsp’의 작성 <%@page import="java.sql.*"%> <html><body> <% 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 + "<br/>"); } rs.close(); stmt.close(); conn.close(); } catch (Exception e) { out.println(e); } %> <p><a href="insert.jsp">insert</a></p> </body></html>

  19. Database Programming using JSP • ‘insert.jsp’의 작성 <%@page import="java.sql.*"%> <html><body> <% 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); } } %> <form name="form1" method="post" action="insert.jsp"> <input type="text" name="no" /> <input type="text" name="name" /> <input type="submit" value="OK" /> </form> <p><a href="list.jsp">list</a></p> </body></html>

  20. Overview of Application Building • Telnet + FTP + MySQL console ike.ie.pusan.ac.kr Telnet daemon shell MySQL Database Internet file system Tomcat FTP daemon JSP page (program)

  21. Database Application • Multi-tier architecture back-end front-end Network business logic + presentation layer DB back-end front-end Network presentation layer business logic DB

  22. Discussion • HTML vs. JSP • 한글? • 숙제의 의미?

More Related