List of commits:
Subject Hash Author Date (UTC)
Some notes in DB applications added. 3535d187737aea90413e73489729a4a64ce89f80 caubert 2021-03-17 13:55:48
Fixed typo cfc6ac63d8ed0d0a2b9f4f530524d4723f5baae6 caubert 2021-03-12 18:36:32
fixed couple of typos. 6191d6cc01638c07ab0b48a086718fc2440fa367 caubert 2021-03-12 18:31:47
Added quiz #2$ ff134e831427d6e24603af76be52576928dae301 caubert 2021-03-01 19:51:12
Added missing file. d7f2b8ceb14456db8ee2857fcd2b9445bcff1f95 caubert 2021-02-16 18:54:57
Added more complex queries and triggers for HW_Vaccine. 1b133f143e9c6fec72271de28345df39689235f8 caubert 2021-02-09 20:23:30
Added project 1 and its solution. 14f03a1733c084b26dbc72c009e2b7b832ed8643 caubert 2021-02-06 21:46:04
Added project 1 and its solution. b7a31871ebccbf4caff81d9d57ed6847f4dc5543 caubert 2021-02-06 21:45:24
Added simple examples for SQL. 4ea62f6930ff19bcff8d406d95c9cd84c0f0216d caubert 2021-02-02 22:24:41
Added first project. e851058cc58a9d47ada9970f8b914e798c7d2ce7 caubert 2021-01-27 19:57:12
Few typos. 45ba15cd03fab4388439b617c656f52b2ec96319 caubert 2021-01-26 20:08:24
Small fix in code. 7860e391d0bbe82336b8f05585f846e829d181b1 caubert 2021-01-26 18:55:17
Fixed various bugs. fa76c1e469a4263d7bb7da79532abd1eedcc49be caubert 2021-01-22 19:27:01
First quizz, and fix bug with code displayed. bc9b6bb097e30186805b02dc1cdc5de2d5feabe4 caubert 2021-01-22 19:21:54
Edited the preamble. 364e709107602e163ea9365f25ccf1f5a6bb1914 caubert 2021-01-11 16:00:07
Started to edit notes and add final exam from fall 2020. bb747e27ce08ce17e91913e947614e3057580995 caubert 2021-01-06 22:26:07
Integrated the include-link feature of pandoc-include-code. 3a8f9ededdaa1f05d526742f5d447aaa017e1d1b caubert 2021-01-04 22:52:18
Fixed citeproc. 0d90c7e60e4a4474fd7ded03bb6526ea63a57253 aubert@math.cnrs.fr 2020-12-27 21:33:48
(Finally) updated pandoc and pandoc-numbering. 127c1964a0732b49e14b46fdb0d3f8446e3892d0 aubert@math.cnrs.fr 2020-12-27 21:14:31
Fixed url in comments, avoid them being wrapped. 09a6a78479f24b5749605a4cb7136f8cfbf57d30 aubert@math.cnrs.fr 2020-12-18 18:55:50
Commit 3535d187737aea90413e73489729a4a64ce89f80 - Some notes in DB applications added.
Author: caubert
Author date (UTC): 2021-03-17 13:55
Committer name: caubert
Committer date (UTC): 2021-03-17 13:55
Parent(s): cfc6ac63d8ed0d0a2b9f4f530524d4723f5baae6
Signer:
Signing key:
Signing status: N
Tree: d241395565d4a33e9dfbd5f072374eaeec2896d4
File Lines added Lines deleted
notes/lectures_notes.md 14 8
File notes/lectures_notes.md changed (mode: 100644) (index 5d231c5..fd13d62)
... ... Every database application follows the same routine:
8509 8509 #. Terminate / close the connection with the DBMS. #. Terminate / close the connection with the DBMS.
8510 8510
8511 8511 Which API is used vary with the pair Language / DBMS. Which API is used vary with the pair Language / DBMS.
8512 Here are some of the most commonly used pairs:
8512 Here are some of the most commonly used pairs for MySQL (that may be compatible with other DBMS in some cases):
8513 8513
8514 8514 | Language | API | Website | Language | API | Website
8515 8515 --- | ------- | ------------- --- | ------- | -------------
 
... ... C# | MySQL Connector/Net | <https://dev.mysql.com/downloads/connector/net/8.0.ht
8519 8519 Java | Java DataBase Connectivity | <https://docs.oracle.com/javase/9/docs/api/java/sql/package-summary.html> Java | Java DataBase Connectivity | <https://docs.oracle.com/javase/9/docs/api/java/sql/package-summary.html>
8520 8520
8521 8521 In this chapter, we will _more precisely_ study how to develop a database application _coded in Java_ that uses _the Java DataBase Connectivity_ library. In this chapter, we will _more precisely_ study how to develop a database application _coded in Java_ that uses _the Java DataBase Connectivity_ library.
8522 If you were to work with a different API in your future life, you would likely realize that most of what we will be studying remains true: reading the documentation and understanding the general strategy is what matters in this chapter, to build comfidence in your capacities.
8522 8523
8523 8524 ## Java's Way ## Java's Way
8524 8525
 
... ... For a quick introduction to Java, cf. <https://spots.augusta.edu/caubert/teachin
8542 8543 ## A First Program ## A First Program
8543 8544
8544 8545 We will write and compile a simple java program that manipulates a simple database^[This program ows a lot to the one presented at <http://www.ntu.edu.sg/home/ehchua/programming/java/jdbc_basic.html>.]. We will write and compile a simple java program that manipulates a simple database^[This program ows a lot to the one presented at <http://www.ntu.edu.sg/home/ehchua/programming/java/jdbc_basic.html>.].
8545 Even if the creation and population of the database could have been done from within the program, we will do it as a preliminary step, using the C.L.I., to make our program simpler.
8546 Even if the creation and population of the database could have been done from within the program, we will do it as a preliminary step, using the C.L.I., to make our program simpler (and also because it generally match usage: schemas are usually created before the program is executed).
8546 8547
8547 8548 ### The Database (`SQL`) ### The Database (`SQL`)
8548 8549
 
... ... at FirstProg.main(FirstProg.java:9)
8642 8643
8643 8644 A couple of comments: A couple of comments:
8644 8645
8645 - `java.sql.*`, whose documentation is at <https://docs.oracle.com/javase/8/docs/api/java/sql/package-summary.html>, contains the classes
8646 - `java.sql.*`, whose documentation is at <https://docs.oracle.com/javase/8/docs/api/java/sql/package-summary.html>, contains the following classes that we will use in this chapter:
8646 8647 - `DriverManager`, used for managing a set of JDBC drivers, - `DriverManager`, used for managing a set of JDBC drivers,
8647 8648 - `Connection`, used to make a connection with a database via `DriverManager` objects, - `Connection`, used to make a connection with a database via `DriverManager` objects,
8648 8649 - `Statement`, used to send basic `SQL` statements via `Connection` objects, - `Statement`, used to send basic `SQL` statements via `Connection` objects,
8649 8650 - `ResultSet`, to retrieve and update the results of a query, returned by a `Statement` object, - `ResultSet`, to retrieve and update the results of a query, returned by a `Statement` object,
8650 - `ResultSetMetadata`, to get information about the columns of a `ResultSet` object,
8651 - `ResultSetMetadata`, to get information about a `ResultSet` object,
8651 8652 - `SQLException`, a class of exceptions relative to `SQL`. - `SQLException`, a class of exceptions relative to `SQL`.
8652 8653
8653 8654 - Intuitively, a `Connection` is a bridge (the physical connection), and `Statement` is a lane (a symbolic, or logic, path on the bridge). - Intuitively, a `Connection` is a bridge (the physical connection), and `Statement` is a lane (a symbolic, or logic, path on the bridge).
 
... ... A couple of comments:
8659 8660 - `HW_EBOOKSHOP` is the schema (that needs to already exist in this case). - `HW_EBOOKSHOP` is the schema (that needs to already exist in this case).
8660 8661
8661 8662 - Note that `strSelect` does not end with `;` (it could, but does not have to). - Note that `strSelect` does not end with `;` (it could, but does not have to).
8662 - `next()` returns `true` if there is something left in the set of result, and move to the next line if it is the case. It ressembles what we would use to read from a file. If you try to use `getString` _before_ moving to the first row, you'll get an error like `java.sql.SQLException: Before start of result set`: indeed, the cursor is "above" the first row of results when the `ResultSet` object is created.
8663 - `next()` returns `true` if there is something left in the set of result, and move to the next line if it is the case. It ressembles what we would use to read from a file. If you try to use `getString` _before_ moving to the first row, you'll get an error like
8664 ```
8665 java.sql.SQLException: Before start of result set
8666 ```
8667 Undeed, the cursor is "above" the first row of results when the `ResultSet` object is created.
8663 8668 - We could use `1`, `2`, and `3` instead of `"title"`, `"price"` and `"qty"` in the `while` loop: the `getString`, `getDouble` and `getInt` are overloaded, and have versions that take one integer as input, corresponding to the position of the attribute in the result set. - We could use `1`, `2`, and `3` instead of `"title"`, `"price"` and `"qty"` in the `while` loop: the `getString`, `getDouble` and `getInt` are overloaded, and have versions that take one integer as input, corresponding to the position of the attribute in the result set.
8664 8669
8665 8670
 
... ... But, actually, `SQL` and `JAVA` datatypes can be mapped as follows:
8728 8733 `REAL` | `float` `REAL` | `float`
8729 8734 `DOUBLE` | ` double` `DOUBLE` | ` double`
8730 8735 `DECIMAL(t,d)` | `java.math.BigDecimal` `DECIMAL(t,d)` | `java.math.BigDecimal`
8731 `DATE` | `java.sql.date`
8736 `DATE` | `java.sql.Date`
8732 8737 `BOOLEAN` | `boolean` `BOOLEAN` | `boolean`
8733 8738 `BIT(1)` | `byte` `BIT(1)` | `byte`
8734 8739
8735 (`DECIMAL(t,d)` was not previously introduced: the `t` stands for the number of digits, the `d` for the precision.)
8740 Remember that in `DECIMAL(t,d)` the `t` stands for the number of digits, the `d` for the precision.
8736 8741
8737 We cannot always have that correspondance: what would correspond to a reference variable?
8742 However, we cannot always have a correspondance going the other way around (from Java to SQL): what would correspond to a reference variable?
8738 8743 To a private attribute? To a private attribute?
8739 8744 This series of problems is called "object-relational impedance mismatch", it can be overcomed, but at a cost. This series of problems is called "object-relational impedance mismatch", it can be overcomed, but at a cost.
8745 We will come back to this in the [Presentation of NoSQL](#presentation-of-nosql) Chapter.
8740 8746
8741 8747
8742 8748 ## Differences Between `executeQuery`, `executeUpdate` and `execute` ## Differences Between `executeQuery`, `executeUpdate` and `execute`
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/caubert/CSCI_3410

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/caubert/CSCI_3410

Clone this repository using git:
git clone git://git.rocketgit.com/user/caubert/CSCI_3410

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main