Date post: | 12-Jan-2016 |
Category: |
Documents |
Upload: | ophelia-dalton |
View: | 225 times |
Download: | 0 times |
Database Programmingusing JSP and MySQL
2003.4.13
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
Network presentation
layerbusiness
logic DB
front-end
back-end
Network business logic +
presentation layer DB
Our Database Application
게시판
front-end
back-end
Network business logic +
presentation layer DB
Web browser JSP page MySQLInternet
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
Telnetdaemon
Internet
FTPdaemon
shell
filesystem
JSP page(program)
Database
Tomcat
MySQL
ike.ie.pusan.ac.kr
Telnetdaemon
Internet
FTPdaemon
shell
filesystem
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
Telnetdaemon
Internet
FTPdaemon
shell
filesystem
JSP page(program)
Database
Tomcat
MySQL
지금 한 것
File System Access via FTP
테스트 Web page 작성1. 시작 실행 “ notepad”
2. 다음을 입력
3. 바탕 화면에 ‘ test.html’ 로 저장
<html><body>
<h1>Hello! HTML!</h1>
</body></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 실행 http://ike.ie.pusan.ac.kr:8080/uXXXXX/test.html
File System Access via FTP
지금 한 것
ike.ie.pusan.ac.kr
Telnetdaemon
Internet
FTPdaemon
shell
filesystem
JSP page(program)
Database
Tomcat
MySQL
File System Access via FTP
1. MySQL 을 종료함
2. 현재 경로의 내용확인 ls
3. ‘test.html’ 확인 cd webapps ls
ike.ie.pusan.ac.kr
Telnetdaemon
Internet
FTPdaemon
shell
filesystem
JSP page(program)
Database
Tomcat
MySQL
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>
Our First JSP Programming
1. ‘test.jsp’ 를 ike 로 전송
2. 결과 확인
ike.ie.pusan.ac.kr
Telnetdaemon
Internet
FTPdaemon
shell
filesystem
JSP page(program)
Database
Tomcat
MySQL
<html><body>
<h1><%= "Hello, JSP! " %></h1>
<%String str = request.getParameter("name");if (str != null) {
out.println("You have input " + s);}%>
<hr/>
<form name="form1" method="post" action="test.jsp">Your input? <input type="text" name="name" /><input type="submit" value="OK" /></form>
</body></html>
Our First JSP Programming
만일 오류가 있다면 ?
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>
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>
Overview of Application Building
Telnet + FTP + MySQL console
ike.ie.pusan.ac.kr
Telnetdaemon
Internet
FTPdaemon
shell
filesystem
JSP page(program)
Database
Tomcat
MySQL
Database Application
Multi-tier architecture
front-end
back-end
Network presentation
layerbusiness
logic DB
front-end
back-end
Network business logic +
presentation layer DB
Discussion
HTML vs. JSP
한글 ?
숙제의 의미 ?