File notes/lectures_notes.md changed (mode: 100644) (index 5806c4f..8df2598) |
... |
... |
For a quick introduction to Java, cf. <http://spots.augusta.edu/caubert/teaching |
5820 |
5820 |
|
|
5821 |
5821 |
## A First Program |
## A First Program |
5822 |
5822 |
|
|
5823 |
|
### The Java code |
|
5824 |
|
|
|
5825 |
|
~~~{.java .numberLines} |
|
5826 |
|
// javac FirstProg.java |
|
5827 |
|
// java -cp .:mysql-connector-java-5.1.44/mysql-connector-java-5.1.44-bin.jar FirstProg |
|
5828 |
|
import java.sql.*; |
|
5829 |
|
|
|
5830 |
|
public class FirstProg { |
|
5831 |
|
public static void main(String[] args) { |
|
5832 |
|
try ( |
|
5833 |
|
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/HW_EBOOKSHOP", "testuser","password"); |
|
5834 |
|
Statement stmt = conn.createStatement(); |
|
5835 |
|
) { |
|
5836 |
|
String strSelect = "SELECT title, price, qty FROM books WHERE qty > 40"; |
|
5837 |
|
System.out.print("The SQL query is: " + strSelect + "\n"); |
|
5838 |
|
ResultSet rset = stmt.executeQuery(strSelect); |
|
5839 |
|
|
|
5840 |
|
System.out.println("The records selected are:"); |
|
5841 |
|
int rowCount = 0; |
|
5842 |
|
String title; |
|
5843 |
|
double price; |
|
5844 |
|
int qty; |
|
5845 |
|
|
|
5846 |
|
while(rset.next()) { |
|
5847 |
|
title = rset.getString("title"); |
|
5848 |
|
price = rset.getDouble("price"); |
|
5849 |
|
qty = rset.getInt("qty"); |
|
5850 |
|
System.out.println(title + ", " + price + ", " + qty); |
|
5851 |
|
rowCount++; |
|
5852 |
|
} |
|
5853 |
|
|
|
5854 |
|
System.out.println("Total number of records = " + rowCount); |
|
5855 |
|
conn.close(); |
|
5856 |
|
|
|
5857 |
|
} catch(SQLException ex) { |
|
5858 |
|
ex.printStackTrace(); |
|
5859 |
|
} |
|
5860 |
|
} |
|
5861 |
|
} |
|
5862 |
|
~~~ |
|
5863 |
|
|
|
5864 |
|
A couple of comments: |
|
5865 |
|
|
|
5866 |
|
- `java.sql.*` contains the classes `Connection`, `Statement`, `ResultSet`, `ResultSetMetadata`. |
|
5867 |
|
- In the string `"jdbc:mysql://localhost:3306/HW_EBOOKSHOP"`, `jdbc` is the protocol, `mysql` is the subprotocol, `localhost` is the url of the database, `3306` is the port, and `HW_EBOOKSHOP` is the schema (that needs to already exist in this case). |
|
5868 |
|
- Note that `strSelect` doesn't end with `;` (it could, but doesn't have to). |
|
5869 |
|
- `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 is close to the code we would use to read from a file. |
|
5870 |
|
- We could use `1`, `2`, and `3` instead of `"title"`, `"price"` and `"qty"` in the `while` loop: `getString`, `getDouble` and `getInt` also take integers, corresponding to the position of the attribute in the result set. |
|
|
5823 |
|
We will write and compile a simple java program that manipulates a simple database. |
|
5824 |
|
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. |
5871 |
5825 |
|
|
|
5826 |
|
### The database (`sql`) |
5872 |
5827 |
|
|
5873 |
|
### The database |
|
|
5828 |
|
For this program, we will use the following database: |
5874 |
5829 |
|
|
5875 |
5830 |
```{.sqlmysql .numberLines include=code/sql/HW_EBOOKSHOP.sql} |
```{.sqlmysql .numberLines include=code/sql/HW_EBOOKSHOP.sql} |
5876 |
5831 |
``` |
``` |
5877 |
5832 |
|
|
5878 |
|
|
|
5879 |
5833 |
~~~{.plain .numberlines} |
~~~{.plain .numberlines} |
5880 |
5834 |
MariaDB [HW_EBOOKSHOP]> SELECT * FROM books; |
MariaDB [HW_EBOOKSHOP]> SELECT * FROM books; |
5881 |
5835 |
+------+----------------------------+--------------+-------+------+ |
+------+----------------------------+--------------+-------+------+ |
|
... |
... |
MariaDB [HW_EBOOKSHOP]> SELECT * FROM books; |
5890 |
5844 |
5 rows in set (0.00 sec) |
5 rows in set (0.00 sec) |
5891 |
5845 |
~~~ |
~~~ |
5892 |
5846 |
|
|
|
5847 |
|
You can copy and paste the code, then execute it, or use MySQL's batch mode: you can find the code previously given at `code/sql/HW_EBOOKSHOP.sql`, i.e., at <https://rocketgit.com/user/caubert/CSCI_3410/source/tree/branch/master/blob/notes/code/sql/HW_EBOOKSHOP.sql>. |
|
5848 |
|
Open a terminal (or command-line interpreter), navigate to the folder where you stored that file (using `cd`), and type |
|
5849 |
|
|
|
5850 |
|
~~~{.bash} |
|
5851 |
|
mysql -u testuser -p < HW_EBOOKSHOP.sql |
|
5852 |
|
~~~ |
|
5853 |
|
|
|
5854 |
|
for linux, or (something like) |
|
5855 |
|
|
|
5856 |
|
~~~{.bash} |
|
5857 |
|
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" -u testuser -p < HW_EBOOKSHOP.sql |
|
5858 |
|
~~~ |
|
5859 |
|
|
|
5860 |
|
for Windows. |
|
5861 |
|
|
|
5862 |
|
You just discovered MySQL's batch mode, that perform *series* of instructions from a file. |
|
5863 |
|
You can easily make sure that the database and the table were indeed created, and the values inserted, by logging the way you used to, and executing the usual commands. |
|
5864 |
|
|
|
5865 |
|
### Executing Database application |
|
5866 |
|
|
|
5867 |
|
As we're about to see, a database application needs to be written following this order: |
|
5868 |
|
|
|
5869 |
|
#. Load the API, |
|
5870 |
|
#. Try to open the connection, using a try/catch statement. |
|
5871 |
|
#. Perform the required actions on the database. |
|
5872 |
|
#. Close the connection. |
|
5873 |
|
|
|
5874 |
|
Of course, if the second step failed, then the program needs to exit gracefully, or to provide debugging information to the user. |
|
5875 |
|
The program we will obtain can (normally) be compiled, using something like `javac FirstProg.java`{.bash} (or an equivalent command for windows). |
|
5876 |
|
But another refinment is needed when you want to compile it. |
|
5877 |
|
We need to set up the *driver* (or *connector*) to make the java `sql` API and MySQL communicate. To do so, |
|
5878 |
|
|
|
5879 |
|
- Go to <https://dev.mysql.com/downloads/connector/j/> |
|
5880 |
|
- Click on "Download" in front of "Platform Independent (Architecture Independent), ZIP Archive" |
|
5881 |
|
- Look for the (somewhat hidden) "No thanks, just start my download." |
|
5882 |
|
- Download the file named "mysql-connector-java-***.zip", where `***` is the version number. |
|
5883 |
|
- Unzip the file, and locate the "mysql-connector-java-***-bin.jar" file. |
|
5884 |
|
- Copy that file in the same folder as where you intend to write your program. |
|
5885 |
|
|
|
5886 |
|
Once this is done and your program was compiled, you can run it using (where you replace `***` with the actual number, of course, e.g. `8.0.15`): |
|
5887 |
|
|
|
5888 |
|
~~~{.bash} |
|
5889 |
|
java -cp .:mysql-connector-java-***-bin.jar FirstProg |
|
5890 |
|
~~~ |
|
5891 |
|
|
|
5892 |
|
in Linux, or |
|
5893 |
|
|
|
5894 |
|
~~~{.bash} |
|
5895 |
|
java -cp .;mysql-connector-java-***-bin.jar FirstProg |
|
5896 |
|
~~~ |
|
5897 |
|
|
|
5898 |
|
in Windows. |
|
5899 |
|
The `-cp` option lists the places where java should look for the class used in the program: we are explicitely asking java to use the `mysql-connector-java-***-bin.jar` executable to execute our `FirstProg` executable. |
|
5900 |
|
|
|
5901 |
|
If we try to execute `FirstProg` without that flag, we obtain the following error message: |
|
5902 |
|
|
|
5903 |
|
~~~{.bash} |
|
5904 |
|
$ java FirstProg |
|
5905 |
|
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/HW_EBOOKSHOP |
|
5906 |
|
at java.sql.DriverManager.getConnection(DriverManager.java:689) |
|
5907 |
|
at java.sql.DriverManager.getConnection(DriverManager.java:247) |
|
5908 |
|
at FirstProg.main(FirstProg.java:9) |
|
5909 |
|
~~~ |
|
5910 |
|
|
|
5911 |
|
### The application program (`java`) |
|
5912 |
|
|
|
5913 |
|
|
|
5914 |
|
```{.java .numberLines include=code/java/FirstProg.java} |
|
5915 |
|
``` |
|
5916 |
|
|
|
5917 |
|
|
|
5918 |
|
A couple of comments: |
|
5919 |
|
|
|
5920 |
|
- `java.sql.*` contains the classes `Connection`, `Statement`, `ResultSet`, `ResultSetMetadata`. |
|
5921 |
|
- In the string `"jdbc:mysql://localhost:3306/HW_EBOOKSHOP"`, `jdbc` is the protocol, `mysql` is the subprotocol, `localhost` is the url of the database, `3306` is the port, and `HW_EBOOKSHOP` is the schema (that needs to already exist in this case). |
|
5922 |
|
- Note that `strSelect` doesn't end with `;` (it could, but doesn't have to). |
|
5923 |
|
- `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 is close to the code we would use to read from a file. |
|
5924 |
|
- We could use `1`, `2`, and `3` instead of `"title"`, `"price"` and `"qty"` in the `while` loop: `getString`, `getDouble` and `getInt` also take integers, corresponding to the position of the attribute in the result set. |
|
5925 |
|
|
|
5926 |
|
|
5893 |
5927 |
### The result |
### The result |
5894 |
5928 |
|
|
5895 |
5929 |
If you store the program in `FirstProg.java`, compile it, with |
If you store the program in `FirstProg.java`, compile it, with |
|
... |
... |
javac FirstProg.java |
5901 |
5935 |
and then execute it, with |
and then execute it, with |
5902 |
5936 |
|
|
5903 |
5937 |
~~~{.bash} |
~~~{.bash} |
5904 |
|
java -cp .:mysql-connector-java-5.1.44/mysql-connector-java-5.1.44-bin.jar FirstProg |
|
|
5938 |
|
java -cp .:mysql-connector-java-8.0.15.jar FirstProg |
5905 |
5939 |
~~~ |
~~~ |
5906 |
5940 |
|
|
5907 |
5941 |
then you would obtain: |
then you would obtain: |
|
... |
... |
The records selected are: |
5952 |
5986 |
## Mapping Datatypes |
## Mapping Datatypes |
5953 |
5987 |
|
|
5954 |
5988 |
`SQL` | `JAVA` | |
`SQL` | `JAVA` | |
5955 |
|
--- | --- |
|
|
5989 |
|
:---: | :---: |
5956 |
5990 |
`INTEGER` | `int` |
`INTEGER` | `int` |
5957 |
5991 |
`CHARACTER(n)` | `String` |
`CHARACTER(n)` | `String` |
5958 |
5992 |
`VARCHAR(n)` | `String` |
`VARCHAR(n)` | `String` |
|
... |
... |
For more details, consult <https://docs.oracle.com/javase/7/docs/api/java/sql/St |
5982 |
6016 |
|
|
5983 |
6017 |
## A Second Program |
## A Second Program |
5984 |
6018 |
|
|
|
6019 |
|
The program in [%D %n (%T)](#problem:Advanced_java) uses the modifications discussed below. |
|
6020 |
|
|
5985 |
6021 |
### Passing options |
### Passing options |
5986 |
6022 |
|
|
5987 |
6023 |
We can pass options when connecting to the database: |
We can pass options when connecting to the database: |
5988 |
6024 |
|
|
5989 |
6025 |
~~~{.java} |
~~~{.java} |
5990 |
6026 |
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/HW_DBPROG" |
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/HW_DBPROG" |
5991 |
|
+ "?user=testuser" |
|
5992 |
|
+ "&password=password" |
|
5993 |
|
+ "&allowMultiQueries=true" |
|
5994 |
|
+ "&createDatabaseIfNotExist=true" |
|
5995 |
|
+ "&useSSL=true"); |
|
|
6027 |
|
+ "?user=testuser" |
|
6028 |
|
+ "&password=password" |
|
6029 |
|
+ "&allowMultiQueries=true" |
|
6030 |
|
+ "&createDatabaseIfNotExist=true" |
|
6031 |
|
+ "&useSSL=true"); |
5996 |
6032 |
~~~ |
~~~ |
5997 |
6033 |
|
|
5998 |
6034 |
`createDatabaseIfNotExist` is about schema, actually. |
`createDatabaseIfNotExist` is about schema, actually. |
|
... |
... |
Compared to executing SQL statements directly, prepared statements have three ma |
6028 |
6064 |
|
|
6029 |
6065 |
You can pass options when creating Statement objects to be able to read it both ways, and to be able to update rows. |
You can pass options when creating Statement objects to be able to read it both ways, and to be able to update rows. |
6030 |
6066 |
|
|
6031 |
|
**COPY HOMEWORK HERE** |
|
6032 |
|
|
|
6033 |
6067 |
## Exercises {-} |
## Exercises {-} |
6034 |
6068 |
|
|
6035 |
6069 |
Exercise +.# |
Exercise +.# |
|
... |
... |
Exercise +.# |
6060 |
6094 |
~ |
~ |
6061 |
6095 |
|
|
6062 |
6096 |
Explain this JDBC URL format: |
Explain this JDBC URL format: |
6063 |
|
|
|
6064 |
|
~~~{.java .numberLines} |
|
6065 |
|
jdbc:mysql://localhost:3306/HW_NewDB?createDatabaseIfNotExist=true&useSSL=true |
|
6066 |
|
~~~ |
|
|
6097 |
|
|
|
6098 |
|
~~~{.java .numberLines} |
|
6099 |
|
jdbc:mysql://localhost:3306/HW_NewDB?createDatabaseIfNotExist=true&useSSL=true |
|
6100 |
|
~~~ |
6067 |
6101 |
|
|
6068 |
6102 |
Exercise +.# |
Exercise +.# |
6069 |
6103 |
|
|
|
... |
... |
Solution +.# |
6099 |
6133 |
|
|
6100 |
6134 |
Solution +.# |
Solution +.# |
6101 |
6135 |
|
|
6102 |
|
: It checks if there is data to read, and if move the cursor reads it. |
|
|
6136 |
|
: It checks if there is data to read, and if there is, it moves the cursor to read it. |
6103 |
6137 |
It returns a Boolean. |
It returns a Boolean. |
6104 |
6138 |
|
|
6105 |
6139 |
Solution +.# |
Solution +.# |
|
... |
... |
Solution +.# |
6128 |
6162 |
|
|
6129 |
6163 |
Solution +.# |
Solution +.# |
6130 |
6164 |
~ |
~ |
6131 |
|
|
|
6132 |
|
The errors are the following: |
|
6133 |
|
|
|
6134 |
|
- l. 13: The query is incorrect (`WHERE`{.sqlmysql} should come before `FROM`{.sqylmysql}), |
|
6135 |
|
- TO be written |
|
|
6165 |
|
|
|
6166 |
|
The errors are: |
|
6167 |
|
|
|
6168 |
|
- line 16, `stmt.executeUpdate(strSelect)`{.java}: `executeUpdate`{.java} cannot be used to perform `SELECT`{.sqlmysql} statements. |
|
6169 |
|
- line 21, this error is subtle: we need to display the last record before using `previous()`{.java}, otherwise it would be just skipped. We can fix this using a `do`...`while` loop. |
|
6170 |
|
- line 22, `String title = rset.getDouble("title");`{.java}: `getDouble`{.java} returns a `double`{.java}, and hence cannot be stored as a `String`{.java}. |
|
6171 |
|
- line 28, `ps.executeQuery()`{.java}: the prepared statement did not received a value for the `?` argument. |
|
6172 |
|
|
|
6173 |
|
You can find the program patched in `code/java/ProgWithErrorsPatched.java`, the (relevant) diff. is: |
|
6174 |
|
|
|
6175 |
|
~~~~{.bash} |
|
6176 |
|
16c16 |
|
6177 |
|
< ResultSet rset = stmt.executeUpdate(strSelect); |
|
6178 |
|
--- |
|
6179 |
|
> ResultSet rset = stmt.executeQuery(strSelect); // Error 1 |
|
6180 |
|
21,24c21,24 |
|
6181 |
|
< while(rset.previous()) { |
|
6182 |
|
< String title = rset.getDouble("title"); |
|
6183 |
|
< System.out.println(title + "\n"); |
|
6184 |
|
< } |
|
6185 |
|
--- |
|
6186 |
|
> do { // Error 2 |
|
6187 |
|
> String title = rset.getString("title"); // Error 3 |
|
6188 |
|
> System.out.println(title); // Not an error, but we probably don't need two new lines. |
|
6189 |
|
> }while(rset.previous()); // Error 2 bis |
|
6190 |
|
27a28 |
|
6191 |
|
> ps.setInt(1, 10); // Error 4 |
|
6192 |
|
~~~~ |
6136 |
6193 |
|
|
6137 |
6194 |
<!-- |
<!-- |
6138 |
6195 |
% |
% |
|
... |
... |
Solution +.# |
6154 |
6211 |
|
|
6155 |
6212 |
Here it is: |
Here it is: |
6156 |
6213 |
|
|
6157 |
|
~~~{.java .numberLines} |
|
6158 |
|
import java.sql.*; |
|
6159 |
|
|
|
6160 |
|
public class NullProg { |
|
6161 |
|
public static void main(String[] args) { |
|
6162 |
|
try ( |
|
6163 |
|
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/HW_DBPROG?user=testuser&password=password&createDatabaseIfNotExist=true"); |
|
6164 |
|
Statement stmt = conn.createStatement(); |
|
6165 |
|
) { |
|
6166 |
|
stmt.execute("CREATE TABLE Test (" + |
|
6167 |
|
"A CHAR(25), " + |
|
6168 |
|
"B INTEGER, " + |
|
6169 |
|
"C DOUBLE)"); |
|
6170 |
|
|
|
6171 |
|
String strAdd = "INSERT INTO Test VALUES (NULL, NULL, NULL);"; |
|
6172 |
|
int number_of_row_changed = stmt.executeUpdate(strAdd); |
|
6173 |
|
System.out.print("This last query changed " + number_of_row_changed + " row(s)."); |
|
6174 |
|
|
|
6175 |
|
ResultSet result = stmt.executeQuery("SELECT * FROM Test"); |
|
6176 |
|
|
|
6177 |
|
if (result.next()) { |
|
6178 |
|
System.out.print(result.getString(1) + " " + result.getDouble(2) + " " + result.getInt(3)); |
|
6179 |
|
if (result.getString(1) == null){System.out.print("\nAnd null for CHAR in SQL is null for String in Java.\n");} |
|
6180 |
|
} |
|
6181 |
|
conn.close(); |
|
6182 |
|
} catch (SQLException ex) { |
|
6183 |
|
ex.printStackTrace(); |
|
6184 |
|
} |
|
6185 |
|
} |
|
6186 |
|
} |
|
6187 |
|
~~~ |
|
6188 |
|
|
|
6189 |
|
|
|
6190 |
|
## Problems |
|
6191 |
|
|
|
6192 |
|
Problem (MySQL's batch mode and HW_EBOOKSHOP.sql) +.#mysql_batch |
|
6193 |
|
~ |
|
6194 |
6214 |
|
|
6195 |
|
In the archive, navigate to `code/sql/` and open `HW_EBOOKSHOP.sql`. |
|
6196 |
|
Then, open a terminal (or command-line interpreter), navigate to the folder where you stored that file (using `cd`), and type |
|
6197 |
|
|
|
6198 |
|
~~~{.bash} |
|
6199 |
|
mysql -u testuser -p < HW_EBOOKSHOP.sql |
|
6200 |
|
~~~ |
|
6201 |
|
|
|
6202 |
|
for linux, or (something like) |
|
6203 |
|
|
|
6204 |
|
~~~{.bash} |
|
6205 |
|
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" -u testuser -p < HW_EBOOKSHOP.sql |
|
6206 |
|
~~~ |
|
6207 |
|
|
|
6208 |
|
for Windows. |
|
6209 |
|
|
|
6210 |
|
You just discovered MySQL's batch mode, that perform *series* of instructions from a file. |
|
6211 |
|
You can easily make sure that the database and the table were indeed created, and the values inserted. |
|
6212 |
|
|
|
6213 |
|
--- |
|
6214 |
|
|
|
6215 |
|
Problem (First Database Application) +.#db_application |
|
6216 |
|
~ |
|
6217 |
|
|
|
6218 |
|
This exercise supposes you successfully completed @problem:mysql_batch. |
|
6219 |
|
We will compile and execute your first database application, using Java and MySQL. |
|
6220 |
|
|
|
6221 |
|
- I will assume that you have MySQL installed and set-up as indicated in Homeworks \#1 and \#2. |
|
6222 |
|
- I will assume that you have Java installed. If not, please refer to <http://spots.augusta.edu/caubert/teaching/general/java/> for a simple program and the instructions to compile and execute it. |
|
6223 |
|
- We need to set up the *driver* (or *connector*) to make the java `sql` API and MySQL communicate. To do so, |
|
6224 |
|
- Go to <https://dev.mysql.com/downloads/connector/j/> |
|
6225 |
|
- Click on "Download" in front of "Platform Independent (Architecture Independent), ZIP Archive" |
|
6226 |
|
- Look for the (somewhat hidden) "No thanks, just start my download." |
|
6227 |
|
- You will download a file named "mysql-connector-java-***.zip", where `***` is the version number. |
|
6228 |
|
- Upon completion of the download, unzip the file, and locate the "mysql-connector-java-***-bin.jar" file. |
|
6229 |
|
- Copy that file in `code/java/`. |
|
6230 |
|
- Open a terminal in that same folder, and compile `FirstProg.java`, using `javac FirstProg.java`{.bash} (or an equivalent command for windows). |
|
6231 |
|
Normally, nothing will be printed, but a `FirstProg.class` file will be created. |
|
6232 |
|
- Now, execute that program, using |
|
6233 |
|
~~~{.bash} |
|
6234 |
|
java -cp .:mysql-connector-java-***-bin.jar FirstProg |
|
6235 |
|
~~~ |
|
6236 |
|
|
|
6237 |
|
in Linux, or |
|
|
6215 |
|
```{.java .numberLines include=code/java/TestForNull.java} |
|
6216 |
|
``` |
6238 |
6217 |
|
|
6239 |
|
~~~{.bash} |
|
6240 |
|
java -cp .;mysql-connector-java-***-bin.jar FirstProg |
|
6241 |
|
~~~ |
|
|
6218 |
|
This program should display: |
|
6219 |
|
|
|
6220 |
|
~~~~{.bash} |
|
6221 |
|
This last query changed 1 row(s). |
|
6222 |
|
null 0.0 0 |
|
6223 |
|
And null for CHAR in SQL is null for String in Java. |
|
6224 |
|
~~~~ |
6242 |
6225 |
|
|
6243 |
|
in Windows. |
|
6244 |
|
The `-cp` option lists the places where java should look for the class used in the program: we are explicitely asking java to use the `mysql-connector-java-***-bin.jar` executable to execute our `FirstProg` executable. |
|
6245 |
|
Try to execute `FirstProg` without that flag, and see what happens. |
|
|
6226 |
|
## Problems |
6246 |
6227 |
|
|
6247 |
6228 |
Problem (Advanced Java Programming) +.#Advanced_java |
Problem (Advanced Java Programming) +.#Advanced_java |
6248 |
6229 |
~ |
~ |
6249 |
6230 |
|
|
6250 |
6231 |
Read, execute, break, edit, compile, patch, hack and (most importantly) understand the following program: |
Read, execute, break, edit, compile, patch, hack and (most importantly) understand the following program: |
6251 |
6232 |
|
|
6252 |
|
```{.sqlmysql .numberLines include=code/java/AdvancedProg.java} |
|
|
6233 |
|
```{.java .numberLines include=code/java/AdvancedProg.java} |
6253 |
6234 |
``` |
``` |
6254 |
6235 |
|
|
|
6236 |
|
<!-- |
6255 |
6237 |
## Solution to Selected Problems {-} |
## Solution to Selected Problems {-} |
6256 |
|
|
|
6257 |
|
Solution to @problem:db_application |
|
6258 |
|
~ |
|
6259 |
|
|
|
6260 |
|
Without the flag, we obtain: |
|
6261 |
|
|
|
6262 |
|
~~~{.bash} |
|
6263 |
|
$ java FirstProg |
|
6264 |
|
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/HW_EBOOKSHOP |
|
6265 |
|
at java.sql.DriverManager.getConnection(DriverManager.java:689) |
|
6266 |
|
at java.sql.DriverManager.getConnection(DriverManager.java:247) |
|
6267 |
|
at FirstProg.main(FirstProg.java:9) |
|
6268 |
|
~~~ |
|
6269 |
|
|
|
6270 |
|
--- |
|
|
6238 |
|
--> |
6271 |
6239 |
|
|
6272 |
6240 |
# A Bit About Security |
# A Bit About Security |
6273 |
6241 |
|
|