SlideShare a Scribd company logo
Aug 6, 2024 Advanced Programming
Spring 2002
Henning Schulzrinne
Dept. of Computer Science
Columbia University
Aug 6, 2024 2
Advanced Programming
Spring 2002
SQL basics
 relational database: tables with labeled
columns, combined into database
 columns are atomic types:
create table person (
person integer unsigned auto_increment
primary key,
name varchar(40),
state enum ('', 'AK', 'AL', ...),
biography text,
verified date,
index(name)
)
Aug 6, 2024 3
Advanced Programming
Spring 2002
SQL basics
 Integer: tinyint, smallint,
mediumint, int(eger), bigint
 Floating point: float, double, real
 Decimal: decimal(m,d) (for $)
 Date: date, datetime, timestamp,
time, year
 String: char(N), varchar(N),
tinyblob, tinytext, blob, text,
enum, set
Aug 6, 2024 4
Advanced Programming
Spring 2002
SQL basics
 Retrieval: SELECT field1, field2
FROM table WHERE condition ORDER
BY expression
 Insertion: INSERT table SET
field1=value1,field2=value2, ...
 Update: UPDATE table SET
field1=value1, field2=value2
WHERE expression
 Delete row: DELETE FROM table WHERE
expression
Aug 6, 2024 5
Advanced Programming
Spring 2002
SQL basics: joins
 Join two tables that have a common
value ("product")
 e.g., SELECT lastname,city.name FROM
person,city WHERE city.zip=person.zip AND
lastname='Jones'
Aug 6, 2024 6
Advanced Programming
Spring 2002
SQL
 Get description of table:
$ mysql -h grandcentral -u cs3995 -p
mysql> use grades
mysql> describe students;
+-----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+-------+
| firstname | text | YES | | NULL | |
| lastname | text | YES | | NULL | |
| points | int(11) | YES | | NULL | |
+-----------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)
Aug 6, 2024 7
Advanced Programming
Spring 2002
SQL Python interface
import MySQLdb
import MySQLdb.cursors
try:
db = connect(host='grandcentral',
user='cs3995', passwd='cs3995',
db='grades')
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
c = db.cursor()
c.execute("SELECT ... FROM ...")
results = c.fetchall() # list of tuples
c.close()
Aug 6, 2024 8
Advanced Programming
Spring 2002
SQL Python interface
 Results are just tuples, with fields in
order of table definition
 can also fetch one row at a time:
c.execute("SELECT firstname,lastname FROM
students ORDER BY lastname")
print "<ul>"
while (1):
student = c.fetchone()
if student == None: break
print "<li>", student, student[0]
print "</ul>"
Aug 6, 2024 9
Advanced Programming
Spring 2002
Python SQL – dictionary
cursor
 Map rows to dictionary elements instead of
list elements:
c.close()
c = db.cursor(MySQLdb.cursors.DictCursor)
c.execute("SELECT firstname,lastname FROM
students")
results = c.fetchall()
for row in results:
print "%s, %s" % (row["firstname"],
row["lastname"])
print "%d rows were returned" % c.rowcount
Aug 6, 2024 10
Advanced Programming
Spring 2002
Servlet life cycle
 server application loads ServletClass
 creates instance via no-args
constructor
 servers call servlet's init() method
 server calls service(req, res)
method for each request (often, with
class name as URL), possibly
concurrently
 servers calls destroy() on shutdown
Aug 6, 2024 11
Advanced Programming
Spring 2002
HTTP requests as servlets
 HTTP method GET, PUT, POST, ... 
doGet, doPut, doPost
 subclass of HttpServlet overrides
default implementation
Aug 6, 2024 12
Advanced Programming
Spring 2002
Servlet example
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloClientServlet extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><HEAD><TITLE>Hello Client!</TITLE>" +
"<HEAD><BODY>Hello Client!</BODY><HTML>");
out.close();
}
public String getServletInfo() {
return "HelloClientServlet 1.0 by Stefan Zeiger";
}
}
Aug 6, 2024 13
Advanced Programming
Spring 2002
2-tier architecture
 "client-server", "fat client"
 e.g., ODBC on client (PC), accessing
SQL database
 business logic on PC
 (-) transport data across network
 (-) need applications for each
platform
 (-) need to update applications on
many desktops
Aug 6, 2024 14
Advanced Programming
Spring 2002
n-tier architecture
Aug 6, 2024 15
Advanced Programming
Spring 2002
n-tier architecture
 client tier:
 receives user events (keyboard, mouse)
 presentation of data
 user interface
 e.g., Java applets, web browser, thin client
application
 application-server tier:
 "business logic"  actual data processing,
algorithms
 can be component-based (Java Beans)
Aug 6, 2024 16
Advanced Programming
Spring 2002
n-tier architecture
 Data-server tier
 data storage
 relational and legacy databases
 all tiers could run on same machine, but
usually separated
 HTTP (or SOAP) from client to server
 Corba or SOAP or remote-SQL between server
tiers
 Advantages:
 independent of storage model
 simpler authentication to database

More Related Content

Similar to Web program-SQL.pptx Web program-SQL.pptx (20)

PPT
Db_05.ppt
KamranAli649587
 
PDF
LectDBS_1.pdf
MadhusmitaSahu40
 
PDF
更多的 SQL 和 MySQL
YUCHENG HU
 
PPTX
python programming internship presentation.pptx
vsingh080501
 
PPTX
2nd chapter dbms.pptx
kavitha623544
 
PPT
ch9.ppt
ChinnuJose3
 
PPT
Dbms
philipsinter
 
PDF
Database Systems - Lecture Week 1
Dios Kurniawan
 
PPT
Database management concepts With Normalization
SimbhuAshokC
 
PPT
Database management concepts With Normalization
SimbhuAshokC
 
PPT
Database Management System Lecture SlideCh-2.ppt
StrickerMan
 
PPTX
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptx
AslamNandyal1
 
PPT
dbms.ppt
GeorgeSamaan9
 
PPT
dbms.ppt
KRISHNARAJ207
 
PPT
dbms (1).ppt
UbaidURRahman78
 
PPT
python.ppt python python python python python
ssuser5feb2c1
 
PPT
python.ppt
ssuser696419
 
Db_05.ppt
KamranAli649587
 
LectDBS_1.pdf
MadhusmitaSahu40
 
更多的 SQL 和 MySQL
YUCHENG HU
 
python programming internship presentation.pptx
vsingh080501
 
2nd chapter dbms.pptx
kavitha623544
 
ch9.ppt
ChinnuJose3
 
Database Systems - Lecture Week 1
Dios Kurniawan
 
Database management concepts With Normalization
SimbhuAshokC
 
Database management concepts With Normalization
SimbhuAshokC
 
Database Management System Lecture SlideCh-2.ppt
StrickerMan
 
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptx
AslamNandyal1
 
dbms.ppt
GeorgeSamaan9
 
dbms.ppt
KRISHNARAJ207
 
dbms (1).ppt
UbaidURRahman78
 
python.ppt python python python python python
ssuser5feb2c1
 
python.ppt
ssuser696419
 

Recently uploaded (17)

PDF
Strategic Plan New and Completed Templeted
alvi932317
 
PPTX
Q1 English3 Week5 [email protected]
JenniferCawaling1
 
PPTX
Meloniusk_Communication_Template_best.pptx
howesix147
 
PDF
ContextForge MCP Gateway - the missing proxy for AI Agents and Tools
Mihai Criveti
 
PDF
Empowering Local Language Email with IDN & EAI – Powered by XgenPlus
XgenPlus Technologies
 
PDF
AI security AI security AI security AI security
elite44
 
PDF
Beginning-Laravel-Build-Websites-with-Laravel-5.8-by-Sanjib-Sinha-z-lib.org.pdf
TagumLibuganonRiverB
 
PDF
web application development company in bangalore.pdf
https://dkpractice.co.in/seo.html tech
 
PDF
The Convergence of Threat Behaviors Across Intrusions
Joe Slowik
 
PDF
Materi tentang From Digital Economy to Fintech.pdf
Abdul Hakim
 
PPTX
Class_4_Limbgvchgchgchgchgchgcjhgchgcnked_Lists.pptx
test123n
 
PDF
Clive Dickens RedTech Public Copy - Collaborate or Die
Clive Dickens
 
PPTX
CHAPTER 1 - PART 3 FOR GRADE 11 STUDENTS
FSBTLEDNathanVince
 
PPTX
Lesson 1.1 Career-Opportunities-in-Ict.pptx
lizelgumadlas1
 
PPTX
My Mother At 66! (2).pptx00000000000000000000000000000
vedapattisiddharth
 
PPTX
Ransomware attack and its effects on cyber crimes
ShilpaShreeD
 
PPTX
原版一样(ANU毕业证书)澳洲澳大利亚国立大学毕业证在线购买
Taqyea
 
Strategic Plan New and Completed Templeted
alvi932317
 
Meloniusk_Communication_Template_best.pptx
howesix147
 
ContextForge MCP Gateway - the missing proxy for AI Agents and Tools
Mihai Criveti
 
Empowering Local Language Email with IDN & EAI – Powered by XgenPlus
XgenPlus Technologies
 
AI security AI security AI security AI security
elite44
 
Beginning-Laravel-Build-Websites-with-Laravel-5.8-by-Sanjib-Sinha-z-lib.org.pdf
TagumLibuganonRiverB
 
web application development company in bangalore.pdf
https://dkpractice.co.in/seo.html tech
 
The Convergence of Threat Behaviors Across Intrusions
Joe Slowik
 
Materi tentang From Digital Economy to Fintech.pdf
Abdul Hakim
 
Class_4_Limbgvchgchgchgchgchgcjhgchgcnked_Lists.pptx
test123n
 
Clive Dickens RedTech Public Copy - Collaborate or Die
Clive Dickens
 
CHAPTER 1 - PART 3 FOR GRADE 11 STUDENTS
FSBTLEDNathanVince
 
Lesson 1.1 Career-Opportunities-in-Ict.pptx
lizelgumadlas1
 
My Mother At 66! (2).pptx00000000000000000000000000000
vedapattisiddharth
 
Ransomware attack and its effects on cyber crimes
ShilpaShreeD
 
原版一样(ANU毕业证书)澳洲澳大利亚国立大学毕业证在线购买
Taqyea
 
Ad

Web program-SQL.pptx Web program-SQL.pptx

  • 1. Aug 6, 2024 Advanced Programming Spring 2002 Henning Schulzrinne Dept. of Computer Science Columbia University
  • 2. Aug 6, 2024 2 Advanced Programming Spring 2002 SQL basics  relational database: tables with labeled columns, combined into database  columns are atomic types: create table person ( person integer unsigned auto_increment primary key, name varchar(40), state enum ('', 'AK', 'AL', ...), biography text, verified date, index(name) )
  • 3. Aug 6, 2024 3 Advanced Programming Spring 2002 SQL basics  Integer: tinyint, smallint, mediumint, int(eger), bigint  Floating point: float, double, real  Decimal: decimal(m,d) (for $)  Date: date, datetime, timestamp, time, year  String: char(N), varchar(N), tinyblob, tinytext, blob, text, enum, set
  • 4. Aug 6, 2024 4 Advanced Programming Spring 2002 SQL basics  Retrieval: SELECT field1, field2 FROM table WHERE condition ORDER BY expression  Insertion: INSERT table SET field1=value1,field2=value2, ...  Update: UPDATE table SET field1=value1, field2=value2 WHERE expression  Delete row: DELETE FROM table WHERE expression
  • 5. Aug 6, 2024 5 Advanced Programming Spring 2002 SQL basics: joins  Join two tables that have a common value ("product")  e.g., SELECT lastname,city.name FROM person,city WHERE city.zip=person.zip AND lastname='Jones'
  • 6. Aug 6, 2024 6 Advanced Programming Spring 2002 SQL  Get description of table: $ mysql -h grandcentral -u cs3995 -p mysql> use grades mysql> describe students; +-----------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+-------+ | firstname | text | YES | | NULL | | | lastname | text | YES | | NULL | | | points | int(11) | YES | | NULL | | +-----------+---------+------+-----+---------+-------+ 3 rows in set (0.00 sec)
  • 7. Aug 6, 2024 7 Advanced Programming Spring 2002 SQL Python interface import MySQLdb import MySQLdb.cursors try: db = connect(host='grandcentral', user='cs3995', passwd='cs3995', db='grades') except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) sys.exit(1) c = db.cursor() c.execute("SELECT ... FROM ...") results = c.fetchall() # list of tuples c.close()
  • 8. Aug 6, 2024 8 Advanced Programming Spring 2002 SQL Python interface  Results are just tuples, with fields in order of table definition  can also fetch one row at a time: c.execute("SELECT firstname,lastname FROM students ORDER BY lastname") print "<ul>" while (1): student = c.fetchone() if student == None: break print "<li>", student, student[0] print "</ul>"
  • 9. Aug 6, 2024 9 Advanced Programming Spring 2002 Python SQL – dictionary cursor  Map rows to dictionary elements instead of list elements: c.close() c = db.cursor(MySQLdb.cursors.DictCursor) c.execute("SELECT firstname,lastname FROM students") results = c.fetchall() for row in results: print "%s, %s" % (row["firstname"], row["lastname"]) print "%d rows were returned" % c.rowcount
  • 10. Aug 6, 2024 10 Advanced Programming Spring 2002 Servlet life cycle  server application loads ServletClass  creates instance via no-args constructor  servers call servlet's init() method  server calls service(req, res) method for each request (often, with class name as URL), possibly concurrently  servers calls destroy() on shutdown
  • 11. Aug 6, 2024 11 Advanced Programming Spring 2002 HTTP requests as servlets  HTTP method GET, PUT, POST, ...  doGet, doPut, doPost  subclass of HttpServlet overrides default implementation
  • 12. Aug 6, 2024 12 Advanced Programming Spring 2002 Servlet example import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloClientServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<HTML><HEAD><TITLE>Hello Client!</TITLE>" + "<HEAD><BODY>Hello Client!</BODY><HTML>"); out.close(); } public String getServletInfo() { return "HelloClientServlet 1.0 by Stefan Zeiger"; } }
  • 13. Aug 6, 2024 13 Advanced Programming Spring 2002 2-tier architecture  "client-server", "fat client"  e.g., ODBC on client (PC), accessing SQL database  business logic on PC  (-) transport data across network  (-) need applications for each platform  (-) need to update applications on many desktops
  • 14. Aug 6, 2024 14 Advanced Programming Spring 2002 n-tier architecture
  • 15. Aug 6, 2024 15 Advanced Programming Spring 2002 n-tier architecture  client tier:  receives user events (keyboard, mouse)  presentation of data  user interface  e.g., Java applets, web browser, thin client application  application-server tier:  "business logic"  actual data processing, algorithms  can be component-based (Java Beans)
  • 16. Aug 6, 2024 16 Advanced Programming Spring 2002 n-tier architecture  Data-server tier  data storage  relational and legacy databases  all tiers could run on same machine, but usually separated  HTTP (or SOAP) from client to server  Corba or SOAP or remote-SQL between server tiers  Advantages:  independent of storage model  simpler authentication to database