File notes/code/java/TestingSemicolon.java changed (mode: 100644) (index a525f76..f906c2a) |
1 |
1 |
// code/java/TestingSemicolon.java |
// code/java/TestingSemicolon.java |
2 |
2 |
|
|
3 |
|
// java.util.Scanner is an API to read from the keyboard. |
|
4 |
3 |
import java.sql.*; |
import java.sql.*; |
5 |
|
import java.util.Scanner; |
|
6 |
4 |
|
|
7 |
5 |
public class TestingSemicolon { |
public class TestingSemicolon { |
8 |
6 |
public static void main(String[] args) { |
public static void main(String[] args) { |
|
... |
... |
public class TestingSemicolon { |
10 |
8 |
DriverManager.getConnection( |
DriverManager.getConnection( |
11 |
9 |
"jdbc:mysql://localhost:3306/?user=testuser&password=password" |
"jdbc:mysql://localhost:3306/?user=testuser&password=password" |
12 |
10 |
+ "&allowMultiQueries=true"); |
+ "&allowMultiQueries=true"); |
13 |
|
Statement stmt = |
|
14 |
|
conn.createStatement(); ) { |
|
|
11 |
|
Statement stmt = conn.createStatement(); ) { |
15 |
12 |
stmt.addBatch("DROP SCHEMA IF EXISTS HW_Testing_Semicolon"); |
stmt.addBatch("DROP SCHEMA IF EXISTS HW_Testing_Semicolon"); |
16 |
13 |
stmt.addBatch("CREATE SCHEMA HW_Testing_Semicolon"); |
stmt.addBatch("CREATE SCHEMA HW_Testing_Semicolon"); |
17 |
14 |
stmt.addBatch("USE HW_Testing_Semicolon"); |
stmt.addBatch("USE HW_Testing_Semicolon"); |
|
... |
... |
public class TestingSemicolon { |
21 |
18 |
stmt.executeUpdate("INSERT INTO Test VALUES(1);"); // Ok |
stmt.executeUpdate("INSERT INTO Test VALUES(1);"); // Ok |
22 |
19 |
stmt.executeUpdate("INSERT INTO Test VALUES(1); INSERT INTO Test VALUES(1)"); // Ok |
stmt.executeUpdate("INSERT INTO Test VALUES(1); INSERT INTO Test VALUES(1)"); // Ok |
23 |
20 |
stmt.executeUpdate("INSERT INTO Test VALUES(1); INSERT INTO Test VALUES(1);"); // Ok |
stmt.executeUpdate("INSERT INTO Test VALUES(1); INSERT INTO Test VALUES(1);"); // Ok |
24 |
|
} |
|
25 |
|
catch (SQLException ex) { |
|
|
21 |
|
} catch (SQLException ex) { |
26 |
22 |
ex.printStackTrace(); |
ex.printStackTrace(); |
27 |
23 |
} |
} |
28 |
|
|
|
|
24 |
|
|
29 |
25 |
try (Connection conn = |
try (Connection conn = |
30 |
26 |
DriverManager.getConnection( |
DriverManager.getConnection( |
31 |
|
"jdbc:mysql://localhost:3306/?user=testuser&password=password"); // without + "&allowMultiQueries=true" |
|
32 |
|
Statement stmt = |
|
33 |
|
conn.createStatement(); ) { |
|
|
27 |
|
"jdbc:mysql://localhost:3306/?user=testuser&password=password"); // without + |
|
28 |
|
// "&allowMultiQueries=true" |
|
29 |
|
Statement stmt = conn.createStatement(); ) { |
34 |
30 |
stmt.addBatch("DROP SCHEMA IF EXISTS HW_Testing_Semicolon"); |
stmt.addBatch("DROP SCHEMA IF EXISTS HW_Testing_Semicolon"); |
35 |
31 |
stmt.addBatch("CREATE SCHEMA HW_Testing_Semicolon"); |
stmt.addBatch("CREATE SCHEMA HW_Testing_Semicolon"); |
36 |
32 |
stmt.addBatch("USE HW_Testing_Semicolon"); |
stmt.addBatch("USE HW_Testing_Semicolon"); |
|
... |
... |
public class TestingSemicolon { |
41 |
37 |
// stmt.executeUpdate("INSERT INTO Test VALUES(1);INSERT INTO Test VALUES(1)"); // Not Ok |
// stmt.executeUpdate("INSERT INTO Test VALUES(1);INSERT INTO Test VALUES(1)"); // Not Ok |
42 |
38 |
// stmt.executeUpdate("INSERT INTO Test VALUES(1);INSERT INTO Test VALUES(1);"); // Not Ok |
// stmt.executeUpdate("INSERT INTO Test VALUES(1);INSERT INTO Test VALUES(1);"); // Not Ok |
43 |
39 |
|
|
44 |
|
} |
|
45 |
|
catch (SQLException ex) { |
|
|
40 |
|
} catch (SQLException ex) { |
46 |
41 |
ex.printStackTrace(); |
ex.printStackTrace(); |
47 |
42 |
} |
} |
48 |
|
|
|
49 |
|
|
|
50 |
43 |
} |
} |
51 |
44 |
} |
} |