2020-06-07 12:42
Page 1

Databases

Lecture 9: SQL in software applications

Page 2

Databases in software applications

End-user database access

Page 3

A typical web service infrastructure

Page 4

Databases in software applications

Database connectivity

Page 5

Database connectivity in Java

Page 6
Database connectivity in Java

Using JDBC

Page 7
Database connectivity in Java

Installing the driver

Page 8
Database connectivity in Java

Typical main program

Page 9
Database connectivity in Java

Database Connection

Page 10
Database connectivity in Java

The try-with-resources statement

Page 11
Database connectivity in Java

Executing queries and retrieving the results

Page 12
Database connectivity in Java

If you only expect one row

Page 13
Database connectivity in Java

Insert, delete, update, etc.

Page 14

About using strings for SQL statements (1)

Page 15

About using strings for SQL statements (2)

Page 16

A serious problem

Page 17
A serious problem
Page 18

SQL injection

Page 19

SQL injection attacks

Page 20

An unusual SQL injection example

Page 21

Prepared Statements

Page 22
Prepared Statements

Use prepared statements!

Page 23

Debugging JDBC code

Getting syntax errors or unexpected results?

Page 24

Debugging JDBC code, more hints

Page 25

Database connectivity in Haskell

HDBC

Page 26

Installing HDBC

Page 27

Programming with HDBC

Connecting to a PostgreSQL database

Page 28
Programming with HDBC

Running statements (without query results)

Page 29
Programming with HDBC

Transactions

Page 30
Programming with HDBC

Running statements and retreiving query results

Page 31
Programming with HDBC

SqlValue

Page 32

Strings with placeholders

Page 33

SQL injection example

Bad programming

Page 34
SQL injection example

Good programming

unregisterStudent :: Connection -> String -> String -> IO ()
unregisterStudent conn student course =
  run conn "DELETE FROM Registered WHERE course=? AND student=?"
           [toSql course,toSql student]
Page 35

Prepared Statements

Page 36

Prepared Statements (2)

Page 37

A complete example in Haskell

A mini version of www.imdb.com

Page 38

Concluding remarks

Recommendations

Page 39
Concluding remarks

Pitfalls

Page 40
Concluding remarks

Further reading