From d63f5d5968c80ea29fbaa9cbd99da7e61349b263 Mon Sep 17 00:00:00 2001 From: nidhibhammar <59045594+nidhibhammar@users.noreply.github.com> Date: Mon, 18 Oct 2021 11:59:01 +0530 Subject: [PATCH 1/3] Updated the content for JDBC 42.2.12.3 version Updated the content for JDBC 42.2.12.3 version --- ...ting_sql_commands_with_executeUpdate().mdx | 141 +++++++++++++----- ..._graphical_interface_to_a_java_program.mdx | 4 +- ...cing_client-side_resource_requirements.mdx | 2 +- ...reparedstatements_to_send_sql_commands.mdx | 71 --------- 4 files changed, 110 insertions(+), 108 deletions(-) delete mode 100644 product_docs/docs/jdbc_connector/42.2.12.3/08_advanced_jdbc_connector_functionality/02_using_preparedstatements_to_send_sql_commands.mdx diff --git a/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx b/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx index 1c29182f06f..d8688c24bdc 100644 --- a/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx +++ b/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx @@ -1,5 +1,5 @@ --- -title: "Executing SQL Commands with executeUpdate()" +title: "Executing SQL Commands with executeUpdate() or through PrepareStatement Objects" legacyRedirectsGenerated: # This list is generated by a script. If you need add entries, use the `legacyRedirects` key. @@ -33,21 +33,15 @@ public void updateEmployee(Connection con) { try { - Console console = System.console(); - Statement stmt = con.createStatement(); - - String empno = console.readLine("Employee Number :"); - String ename = console.readLine("Employee Name :"); - int rowcount = stmt.executeUpdate("INSERT INTO emp(empno, ename) - VALUES("+empno+",'"+ename+"')"); + int rowcount = stmt.executeUpdate("INSERT INTO " + + "emp(empno, ename) VALUES(6000,'Jones')"); System.out.println(""); - System.out.println("Success - "+rowcount+" rows affected."); - } - catch(Exception err) - { - System.out.println("An error has occurred."); - System.out.println("See full details below."); - err.printStackTrace(); + System.out.println("Success - "+rowcount+ + " rows affected."); + } catch(Exception err) { + System.out.println("An error has occurred."); + System.out.println("See full details below."); + err.printStackTrace(); } } ``` @@ -55,47 +49,126 @@ public void updateEmployee(Connection con) The `updateEmployee()` method expects a single argument from the caller, a `Connection` object that must be connected to an Advanced Server database: ```text -public void updateEmployee(Connection con) +public void updateEmployee(Connection con); +``` +The `executeUpdate()` method returns the number of rows affected by the SQL statement (an `INSERT` typically affects one row, but an `UPDATE` or `DELETE` statement can affect more). + +```text +int rowcount = stmt.executeUpdate("INSERT INTO emp(empno, ename)" ++" VALUES(6000,'Jones')"); ``` -Next, `updateEmployee()` prompts the user for an employee name and number: +If `executeUpdate()` returns without throwing an error, the call to `System.out.println` displays a message to the user that shows the number of rows affected. ```text -String empno = console.readLine("Employee Number :"); -String ename = console.readLine("Employee Name :"); +System.out.println(""); +System.out.println("Success - "+rowcount+" rows affected."); ``` -`updateEmployee()` concatenates the values returned by `console.readline()` into an `INSERT` statement and pass the result to the `executeUpdate()` method. +The catch block displays an appropriate error message to the user if the program encounters an exception: ```text -int rowcount = stmt.executeUpdate("INSERT INTO emp(empno, ename) -VALUES("+empno+",'"+ename+"')"); +{ +System.out.println("An error has occurred."); +System.out.println("See full details below."); +err.printStackTrace(); +} ``` -For example, if the user enters an employee number of `6000` and a name of `Jones`, the `INSERT` statement passed to `executeUpdate()` will look like this: +You can use `executeUpdate()` with any SQL command that does not return a result set. However, you probably want to use `PrepareStatements` when the queries can be parameterized. + +## Using PreparedStatements to Send SQL Commands + +Many applications execute the same SQL statement over and over again, changing one or more of the data values in the statement between each iteration. If you use a `Statement` object to repeatedly execute a SQL statement, the server must parse, plan, and optimize the statement every time. JDBC offers another `Statement` derivative, the `PreparedStatement` to reduce the amount of work required in such a scenario. + +Listing 1.4 demonstrates invoking a `PreparedStatement` that accepts an employee ID and employee name and inserts that employee information in the `emp` table: ```text -INSERT INTO emp(empno, ename) VALUES(6000, 'Jones'); +public void AddEmployee(Connection con) +{ + try { + Console c = System.console(); + String command = "INSERT INTO emp(empno,ename) VALUES(?,?)"; + PreparedStatement stmt = con.prepareStatement(command); + stmt.setObject(1,new Integer(c.readLine("ID:"))); + stmt.setObject(2,c.readLine("Name:")); + stmt.execute(); + System.out.println("The procedure successfully executed."); + } catch(Exception err) { + System.out.println("An error has occurred."); + System.out.println("See full details below."); + err.printStackTrace(); + } +} ``` +Instead of hard-coding data values in the SQL statement, you insert `placeholders` to represent the values that will change with each iteration. Listing 1.4 shows an `INSERT` statement that includes two placeholders (each represented by a question mark): -The `executeUpdate()` method returns the number of rows affected by the SQL statement (an `INSERT` typically affects one row, but an `UPDATE` or `DELETE` statement can affect more). If `executeUpdate()` returns without throwing an error, the call to `System.out.println` displays a message to the user that shows the number of rows affected. +```text +String command = "INSERT INTO emp(empno,ename) VALUES(?,?)"; +``` +With the parameterized SQL statement in hand, the `AddEmployee()` method can ask the `Connection` object to prepare that statement and return a `PreparedStatement` object: ```text -System.out.println(""); -System.out.println("Success - "+rowcount+" rows affected."); +PreparedStatement stmt = con.prepareStatement(command); ``` -The catch block displays an appropriate error message to the user if the program encounters an exception: +At this point, the `PreparedStatement` has parsed and planned the `INSERT` statement, but it does not know what values to add to the table. Before executing the `PreparedStatement`, you must supply a value for each placeholder by calling a `setter` method. `setObject()` expects two arguments: + + - A parameter number; parameter number one corresponds to the first question mark, parameter number two corresponds to the second question mark, etc. + + - The value to substitute for the placeholder. + +The `AddEmployee()` method prompts the user for an employee ID and name and calls `setObject()` with the values supplied by the user: ```text -{ -System.out.println("An error has occurred."); -System.out.println("See full details below."); -err.printStackTrace(); -} +stmt.setObject(1,new Integer(c.readLine("ID:"))); stmt.setObject(2, c.readLine("Name:")); +``` + +And then asks the PreparedStatement object to execute the statement: + +```text +stmt.execute(); +``` + +If the SQL statement executes as expected, `AddEmployee()` displays a message that confirms the execution. If the server encounters an exception, the error handling code displays an error message. + +Some simple syntax examples using `PreparedStatement` sending SQL commands follow: + +To use the UPDATE command to update a row: + +```text +String command = " UPDATE emp SET ename=? WHERE empno=?"; +PreparedStatement stmt = con.prepareStatement(command); +stmt.setObject(1, c.readLine("Name:")); +stmt.setObject(2,new Integer(c.readLine("ID:"))); +stmt.execute(); +``` + +To use the DROP TABLE command to delete a table from a database: + +```text +String command = "DROP TABLE tableName"; +PreparedStatement stmt = con.prepareStatement(command); +stmt.execute(); +``` + +To use the CREATE TABLE command to add a new table to a database: + +```text +String command = ("CREATE TABLE tablename (fieldname NUMBER(4,2), fieldname2 VARCHAR2(30))"; +PreparedStatement stmt = con.prepareStatement(command); +stmt.execute(); +``` + +To use the ALTER TABLE command to change the attributes of a table: + +```text +String command ="ALTER TABLE tablename ADD COLUMN colname BOOLEAN "; +PreparedStatement stmt = con.prepareStatement(command); +stmt.execute(); ``` -### executeUpdate() Syntax Examples +## executeUpdate() Syntax Examples You can use `executeUpdate()` with any SQL command that does not return a result set. Some simple syntax examples using `executeUpdate()` with SQL commands follow: diff --git a/product_docs/docs/jdbc_connector/42.2.12.3/07_adding_a_graphical_interface_to_a_java_program.mdx b/product_docs/docs/jdbc_connector/42.2.12.3/07_adding_a_graphical_interface_to_a_java_program.mdx index 1984d0a6aee..8eb8abfefa1 100644 --- a/product_docs/docs/jdbc_connector/42.2.12.3/07_adding_a_graphical_interface_to_a_java_program.mdx +++ b/product_docs/docs/jdbc_connector/42.2.12.3/07_adding_a_graphical_interface_to_a_java_program.mdx @@ -9,12 +9,12 @@ legacyRedirectsGenerated:
-With a little extra work, you can add a graphical user interface to a program - the next example (Listing 1.4) demonstrates how to write a Java application that creates a `JTable` (a spreadsheet-like graphical object) and copies the data returned by a query into that `JTable`. +With a little extra work, you can add a graphical user interface to a program - the next example (Listing 1.5) demonstrates how to write a Java application that creates a `JTable` (a spreadsheet-like graphical object) and copies the data returned by a query into that `JTable`. !!! Note The following sample application is a method, not a complete application. To call this method, provide an appropriate main() function and wrapper class. -Listing 1.4 +Listing 1.5 ```text import java.sql.*; diff --git a/product_docs/docs/jdbc_connector/42.2.12.3/08_advanced_jdbc_connector_functionality/01_reducing_client-side_resource_requirements.mdx b/product_docs/docs/jdbc_connector/42.2.12.3/08_advanced_jdbc_connector_functionality/01_reducing_client-side_resource_requirements.mdx index 79598d0a855..aeee8fb18be 100644 --- a/product_docs/docs/jdbc_connector/42.2.12.3/08_advanced_jdbc_connector_functionality/01_reducing_client-side_resource_requirements.mdx +++ b/product_docs/docs/jdbc_connector/42.2.12.3/08_advanced_jdbc_connector_functionality/01_reducing_client-side_resource_requirements.mdx @@ -25,7 +25,7 @@ Batched result sets cannot be used in all situations. Not adhering to the follow ## Modifying the Batch Size of a Statement Object -Limiting the batch size of a `ResultSet` object can speed the retrieval of data and reduce the resources needed by a client-side application. Listing 1.5 creates a `Statement` object with a batch size limited to five rows: +Limiting the batch size of a `ResultSet` object can speed the retrieval of data and reduce the resources needed by a client-side application. Listing 1.6 creates a `Statement` object with a batch size limited to five rows: ```text // Make sure autocommit is off diff --git a/product_docs/docs/jdbc_connector/42.2.12.3/08_advanced_jdbc_connector_functionality/02_using_preparedstatements_to_send_sql_commands.mdx b/product_docs/docs/jdbc_connector/42.2.12.3/08_advanced_jdbc_connector_functionality/02_using_preparedstatements_to_send_sql_commands.mdx deleted file mode 100644 index b1743ad0d7e..00000000000 --- a/product_docs/docs/jdbc_connector/42.2.12.3/08_advanced_jdbc_connector_functionality/02_using_preparedstatements_to_send_sql_commands.mdx +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: "Using PreparedStatements to Send SQL Commands" - -legacyRedirectsGenerated: - # This list is generated by a script. If you need add entries, use the `legacyRedirects` key. - - "/edb-docs/d/jdbc-connector/user-guides/jdbc-guide/42.2.12.3/using_preparedstatements_to_send_sql_commands.html" - - "/edb-docs/d/jdbc-connector/user-guides/jdbc-guide/42.2.12.1/using_preparedstatements_to_send_sql_commands.html" ---- - - - -Many applications execute the same SQL statement over and over again, changing one or more of the data values in the statement between each iteration. If you use a `Statement` object to repeatedly execute a SQL statement, the server must parse, plan, and optimize the statement every time. JDBC offers another `Statement` derivative, the `PreparedStatement` to reduce the amount of work required in such a scenario. - -Listing 1.6 demonstrates invoking a `PreparedStatement` that accepts an employee ID and employee name and inserts that employee information in the `emp` table: - -Listing 1.6 - -```text -public void AddEmployee(Connection con) -{ - try - { - Console c = System.console(); - String command = "INSERT INTO emp(empno,ename) VALUES(?,?)"; - PreparedStatement stmt = con.prepareStatement(command); - stmt.setObject(1,new Integer(c.readLine("ID:"))); - stmt.setObject(2,c.readLine("Name:")); - stmt.execute(); - - System.out.println("The procedure successfully executed."); - } - catch(Exception err) - { - System.out.println("An error has occurred."); - System.out.println("See full details below."); - err.printStackTrace(); - } -} -``` - -Instead of hard-coding data values in the SQL statement, you insert `placeholders` to represent the values that will change with each iteration. Listing 1.6 shows an `INSERT` statement that includes two placeholders (each represented by a question mark): - -```text -String command = "INSERT INTO emp(empno,ename) VALUES(?,?)"; -``` - -With the parameterized SQL statement in hand, the `AddEmployee()` method can ask the `Connection` object to prepare that statement and return a `PreparedStatement` object: - -```text -PreparedStatement stmt = con.prepareStatement(command); -``` - -At this point, the `PreparedStatement` has parsed and planned the `INSERT` statement, but it does not know what values to add to the table. Before executing the `PreparedStatement`, you must supply a value for each placeholder by calling a `setter` method. `setObject()` expects two arguments: - -- A parameter number; parameter number one corresponds to the first question mark, parameter number two corresponds to the second question mark, etc. -- The value to substitute for the placeholder. - -The `AddEmployee()` method prompts the user for an employee ID and name and calls `setObject()` with the values supplied by the user: - -```text -stmt.setObject(1,new Integer(c.readLine("ID:"))); -stmt.setObject(2, c.readLine("Name:")); -``` - -And then asks the `PreparedStatement` object to execute the statement: - -```text -stmt.execute(); -``` - -If the SQL statement executes as expected, `AddEmployee()` displays a message that confirms the execution. If the server encounters an exception, the error handling code displays an error message. From 1af889faaa44fe5c5cb69a8d4d45763938817cee Mon Sep 17 00:00:00 2001 From: nidhibhammar <59045594+nidhibhammar@users.noreply.github.com> Date: Wed, 27 Oct 2021 16:46:03 +0530 Subject: [PATCH 2/3] Updated the content as per comments on EC-1745 Updated the content as per comments on EC-1745 for versions 42.2.12.3 and 42.2.19.1 --- ...ting_sql_commands_with_executeUpdate().mdx | 37 +---- ...ting_sql_commands_with_executeUpdate().mdx | 150 +++++++++++------- ..._graphical_interface_to_a_java_program.mdx | 2 +- ...cing_client-side_resource_requirements.mdx | 2 +- 4 files changed, 97 insertions(+), 94 deletions(-) diff --git a/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx b/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx index d8688c24bdc..c7384a4842b 100644 --- a/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx +++ b/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx @@ -166,39 +166,4 @@ To use the ALTER TABLE command to change the attributes of a table: String command ="ALTER TABLE tablename ADD COLUMN colname BOOLEAN "; PreparedStatement stmt = con.prepareStatement(command); stmt.execute(); -``` - -## executeUpdate() Syntax Examples - -You can use `executeUpdate()` with any SQL command that does not return a result set. Some simple syntax examples using `executeUpdate()` with SQL commands follow: - -To use the `UPDATE` command with `executeUpdate()` to update a row: - -```text -stmt.executeUpdate("UPDATE emp SET ename='"+ename+"' WHERE empno="+empno); -``` - -To use the `DELETE` command with `executeUpdate()` to remove a row from a table: - -```text -stmt.executeUpdate("DELETE FROM emp WHERE empno="+empno); -``` - -To use the DROP TABLE command with executeUpdate() to delete a table from a database: - -```text -stmt.executeUpdate("DROP TABLE tablename"); -``` - -To use the `CREATE TABLE` command with `executeUpdate()` to add a new table to a database: - -```text -stmt.executeUpdate("CREATE TABLE tablename (fieldname NUMBER(4,2), -fieldname2 VARCHAR2(30))"); -``` - -To use the `ALTER TABLE` command with `executeUpdate()` to change the attributes of a table: - -```text -stmt.executeUpdate("ALTER TABLE tablename ADD COLUMN colname BOOLEAN"); -``` +``` \ No newline at end of file diff --git a/product_docs/docs/jdbc_connector/42.2.19.1/06_executing_sql_commands_with_executeUpdate().mdx b/product_docs/docs/jdbc_connector/42.2.19.1/06_executing_sql_commands_with_executeUpdate().mdx index a8091ef5dc7..ee73f3dbd63 100644 --- a/product_docs/docs/jdbc_connector/42.2.19.1/06_executing_sql_commands_with_executeUpdate().mdx +++ b/product_docs/docs/jdbc_connector/42.2.19.1/06_executing_sql_commands_with_executeUpdate().mdx @@ -1,5 +1,5 @@ --- -title: "Executing SQL Commands with executeUpdate()" +title: "Executing SQL Commands with executeUpdate() or through PrepareStatement Objects" --- @@ -10,7 +10,7 @@ In the previous example `ListEmployees` executed a `SELECT` statement using the The signature of the `executeUpdate()` method is: ```text -int executeUpdate(String sqlStatement) + int executeUpdate(String sqlStatement) ``` Provide this method a single parameter of type `String`, containing the SQL command that you wish to execute. @@ -25,103 +25,141 @@ The example that follows demonstrates using the `executeUpdate()` method to add Listing 1.3 ```text -public void updateEmployee(Connection con) -{ - try - { - Console console = System.console(); - Statement stmt = con.createStatement(); - - String empno = console.readLine("Employee Number :"); - String ename = console.readLine("Employee Name :"); - int rowcount = stmt.executeUpdate("INSERT INTO emp(empno, ename) - VALUES("+empno+",'"+ename+"')"); - System.out.println(""); - System.out.println("Success - "+rowcount+" rows affected."); - } - catch(Exception err) - { - System.out.println("An error has occurred."); - System.out.println("See full details below."); - err.printStackTrace(); - } -} + public void updateEmployee(Connection con) + { + try + { + int rowcount = stmt.executeUpdate("INSERT INTO " + + "emp(empno, ename) VALUES(6000,'Jones')"); + System.out.println(""); + System.out.println("Success - "+rowcount+ + " rows affected."); + } catch(Exception err) { + System.out.println("An error has occurred."); + System.out.println("See full details below."); + err.printStackTrace(); + } + } ``` The `updateEmployee()` method expects a single argument from the caller, a `Connection` object that must be connected to an Advanced Server database: ```text -public void updateEmployee(Connection con) + public void updateEmployee(Connection con); ``` - -Next, `updateEmployee()` prompts the user for an employee name and number: +The `executeUpdate()` method returns the number of rows affected by the SQL statement (an `INSERT` typically affects one row, but an `UPDATE` or `DELETE` statement can affect more). ```text -String empno = console.readLine("Employee Number :"); -String ename = console.readLine("Employee Name :"); + int rowcount = stmt.executeUpdate("INSERT INTO emp(empno, ename)" + +" VALUES(6000,'Jones')"); ``` -`updateEmployee()` concatenates the values returned by `console.readline()` into an `INSERT` statement and pass the result to the `executeUpdate()` method. +If `executeUpdate()` returns without throwing an error, the call to `System.out.println` displays a message to the user that shows the number of rows affected. ```text -int rowcount = stmt.executeUpdate("INSERT INTO emp(empno, ename) -VALUES("+empno+",'"+ename+"')"); + System.out.println(""); + System.out.println("Success - "+rowcount+" rows affected."); ``` -For example, if the user enters an employee number of `6000` and a name of `Jones`, the `INSERT` statement passed to `executeUpdate()` will look like this: +The catch block displays an appropriate error message to the user if the program encounters an exception: ```text -INSERT INTO emp(empno, ename) VALUES(6000, 'Jones'); + { + System.out.println("An error has occurred."); + System.out.println("See full details below."); + err.printStackTrace(); + } ``` -The `executeUpdate()` method returns the number of rows affected by the SQL statement (an `INSERT` typically affects one row, but an `UPDATE` or `DELETE` statement can affect more). If `executeUpdate()` returns without throwing an error, the call to `System.out.println` displays a message to the user that shows the number of rows affected. +You can use `executeUpdate()` with any SQL command that does not return a result set. However, you probably want to use `PrepareStatements` when the queries can be parameterized. + +## Using PreparedStatements to Send SQL Commands + +Many applications execute the same SQL statement over and over again, changing one or more of the data values in the statement between each iteration. If you use a `Statement` object to repeatedly execute a SQL statement, the server must parse, plan, and optimize the statement every time. JDBC offers another `Statement` derivative, the `PreparedStatement` to reduce the amount of work required in such a scenario. + +Listing 1.4 demonstrates invoking a `PreparedStatement` that accepts an employee ID and employee name and inserts that employee information in the `emp` table: ```text -System.out.println(""); -System.out.println("Success - "+rowcount+" rows affected."); + public void AddEmployee(Connection con) + { + try { + Console c = System.console(); + String command = "INSERT INTO emp(empno,ename) VALUES(?,?)"; + PreparedStatement stmt = con.prepareStatement(command); + stmt.setObject(1,new Integer(c.readLine("ID:"))); + stmt.setObject(2,c.readLine("Name:")); + stmt.execute(); + System.out.println("The procedure successfully executed."); + } catch(Exception err) { + System.out.println("An error has occurred."); + System.out.println("See full details below."); + err.printStackTrace(); + } + } ``` - -The catch block displays an appropriate error message to the user if the program encounters an exception: +Instead of hard-coding data values in the SQL statement, you insert `placeholders` to represent the values that will change with each iteration. Listing 1.4 shows an `INSERT` statement that includes two placeholders (each represented by a question mark): ```text -{ -System.out.println("An error has occurred."); -System.out.println("See full details below."); -err.printStackTrace(); -} + String command = "INSERT INTO emp(empno,ename) VALUES(?,?)"; ``` +With the parameterized SQL statement in hand, the `AddEmployee()` method can ask the `Connection` object to prepare that statement and return a `PreparedStatement` object: -### executeUpdate() Syntax Examples +```text + PreparedStatement stmt = con.prepareStatement(command); +``` -You can use `executeUpdate()` with any SQL command that does not return a result set. Some simple syntax examples using `executeUpdate()` with SQL commands follow: +At this point, the `PreparedStatement` has parsed and planned the `INSERT` statement, but it does not know what values to add to the table. Before executing the `PreparedStatement`, you must supply a value for each placeholder by calling a `setter` method. `setObject()` expects two arguments: + + - A parameter number; parameter number one corresponds to the first question mark, parameter number two corresponds to the second question mark, etc. + + - The value to substitute for the placeholder. -To use the `UPDATE` command with `executeUpdate()` to update a row: +The `AddEmployee()` method prompts the user for an employee ID and name and calls `setObject()` with the values supplied by the user: ```text -stmt.executeUpdate("UPDATE emp SET ename='"+ename+"' WHERE empno="+empno); + stmt.setObject(1,new Integer(c.readLine("ID:"))); stmt.setObject(2, c.readLine("Name:")); ``` -To use the `DELETE` command with `executeUpdate()` to remove a row from a table: +And then asks the PreparedStatement object to execute the statement: ```text -stmt.executeUpdate("DELETE FROM emp WHERE empno="+empno); + stmt.execute(); ``` -To use the DROP TABLE command with executeUpdate() to delete a table from a database: +If the SQL statement executes as expected, `AddEmployee()` displays a message that confirms the execution. If the server encounters an exception, the error handling code displays an error message. + +Some simple syntax examples using `PreparedStatement` sending SQL commands follow: + +To use the UPDATE command to update a row: ```text -stmt.executeUpdate("DROP TABLE tablename"); + String command = " UPDATE emp SET ename=? WHERE empno=?"; + PreparedStatement stmt = con.prepareStatement(command); + stmt.setObject(1, c.readLine("Name:")); + stmt.setObject(2,new Integer(c.readLine("ID:"))); + stmt.execute(); ``` -To use the `CREATE TABLE` command with `executeUpdate()` to add a new table to a database: +To use the DROP TABLE command to delete a table from a database: ```text -stmt.executeUpdate("CREATE TABLE tablename (fieldname NUMBER(4,2), -fieldname2 VARCHAR2(30))"); + String command = "DROP TABLE tableName"; + PreparedStatement stmt = con.prepareStatement(command); + stmt.execute(); ``` -To use the `ALTER TABLE` command with `executeUpdate()` to change the attributes of a table: +To use the CREATE TABLE command to add a new table to a database: ```text -stmt.executeUpdate("ALTER TABLE tablename ADD COLUMN colname BOOLEAN"); + String command = ("CREATE TABLE tablename (fieldname NUMBER(4,2), fieldname2 VARCHAR2(30))"; + PreparedStatement stmt = con.prepareStatement(command); + stmt.execute(); ``` + +To use the ALTER TABLE command to change the attributes of a table: + +```text + String command ="ALTER TABLE tablename ADD COLUMN colname BOOLEAN "; + PreparedStatement stmt = con.prepareStatement(command); + stmt.execute(); +``` \ No newline at end of file diff --git a/product_docs/docs/jdbc_connector/42.2.19.1/07_adding_a_graphical_interface_to_a_java_program.mdx b/product_docs/docs/jdbc_connector/42.2.19.1/07_adding_a_graphical_interface_to_a_java_program.mdx index 0d12087baa6..a3a8bbad5f7 100644 --- a/product_docs/docs/jdbc_connector/42.2.19.1/07_adding_a_graphical_interface_to_a_java_program.mdx +++ b/product_docs/docs/jdbc_connector/42.2.19.1/07_adding_a_graphical_interface_to_a_java_program.mdx @@ -10,7 +10,7 @@ With a little extra work, you can add a graphical user interface to a program - !!! Note The following sample application is a method, not a complete application. To call this method, provide an appropriate main() function and wrapper class. -Listing 1.4 +Listing 1.5 ```text import java.sql.*; diff --git a/product_docs/docs/jdbc_connector/42.2.19.1/08_advanced_jdbc_connector_functionality/01_reducing_client-side_resource_requirements.mdx b/product_docs/docs/jdbc_connector/42.2.19.1/08_advanced_jdbc_connector_functionality/01_reducing_client-side_resource_requirements.mdx index 6a4e12699b4..9646cb5fc5b 100644 --- a/product_docs/docs/jdbc_connector/42.2.19.1/08_advanced_jdbc_connector_functionality/01_reducing_client-side_resource_requirements.mdx +++ b/product_docs/docs/jdbc_connector/42.2.19.1/08_advanced_jdbc_connector_functionality/01_reducing_client-side_resource_requirements.mdx @@ -21,7 +21,7 @@ Batched result sets cannot be used in all situations. Not adhering to the follow ## Modifying the Batch Size of a Statement Object -Limiting the batch size of a `ResultSet` object can speed the retrieval of data and reduce the resources needed by a client-side application. Listing 1.5 creates a `Statement` object with a batch size limited to five rows: +Limiting the batch size of a `ResultSet` object can speed the retrieval of data and reduce the resources needed by a client-side application. Listing 1.6 creates a `Statement` object with a batch size limited to five rows: ```text // Make sure autocommit is off From 4dc0b6d76a83a24c567c6871661bf78dd0138260 Mon Sep 17 00:00:00 2001 From: nidhibhammar <59045594+nidhibhammar@users.noreply.github.com> Date: Thu, 28 Oct 2021 12:20:36 +0530 Subject: [PATCH 3/3] Updated the content as per comment from Yunxu Updated the content as per comment from Yunxu --- .../06_executing_sql_commands_with_executeUpdate().mdx | 3 ++- .../06_executing_sql_commands_with_executeUpdate().mdx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx b/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx index c7384a4842b..2292926b711 100644 --- a/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx +++ b/product_docs/docs/jdbc_connector/42.2.12.3/06_executing_sql_commands_with_executeUpdate().mdx @@ -121,7 +121,8 @@ At this point, the `PreparedStatement` has parsed and planned the `INSERT` state The `AddEmployee()` method prompts the user for an employee ID and name and calls `setObject()` with the values supplied by the user: ```text -stmt.setObject(1,new Integer(c.readLine("ID:"))); stmt.setObject(2, c.readLine("Name:")); +stmt.setObject(1,new Integer(c.readLine("ID:"))); +stmt.setObject(2, c.readLine("Name:")); ``` And then asks the PreparedStatement object to execute the statement: diff --git a/product_docs/docs/jdbc_connector/42.2.19.1/06_executing_sql_commands_with_executeUpdate().mdx b/product_docs/docs/jdbc_connector/42.2.19.1/06_executing_sql_commands_with_executeUpdate().mdx index ee73f3dbd63..cb309bfe9ee 100644 --- a/product_docs/docs/jdbc_connector/42.2.19.1/06_executing_sql_commands_with_executeUpdate().mdx +++ b/product_docs/docs/jdbc_connector/42.2.19.1/06_executing_sql_commands_with_executeUpdate().mdx @@ -117,7 +117,8 @@ At this point, the `PreparedStatement` has parsed and planned the `INSERT` state The `AddEmployee()` method prompts the user for an employee ID and name and calls `setObject()` with the values supplied by the user: ```text - stmt.setObject(1,new Integer(c.readLine("ID:"))); stmt.setObject(2, c.readLine("Name:")); + stmt.setObject(1,new Integer(c.readLine("ID:"))); + stmt.setObject(2, c.readLine("Name:")); ``` And then asks the PreparedStatement object to execute the statement: