Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Programming » JDBC support » Data access using JDBC

 

Using static INSERT and DELETE statements from JDBC

A sample JDBC application is called from the database server to insert and delete rows in the Departments table using static SQL statements.

Prerequisites

A Java Development Kit (JDK) must be installed.

To create an external procedure, you must have the CREATE PROCEDURE and CREATE EXTERNAL REFERENCE system privileges. You must also have SELECT, DELETE, and INSERT privileges on the database object you are modifying.

 Task
  1. Connect to the database from Interactive SQL.

  2. Ensure the JDBCExample class has been installed.

    For more information about installing the Java examples classes, see Preparing for the JDBC examples.

  3. Define a stored procedure named JDBCExample that acts as a wrapper for the JDBCExample.main method in the class:

    CREATE PROCEDURE JDBCExample(IN arg CHAR(50))
      EXTERNAL NAME 'JDBCExample.main([Ljava/lang/String;)V'
      LANGUAGE JAVA;
  4. Call the JDBCExample.main method as follows:

    CALL JDBCExample( 'insert' );

    The argument string 'insert' causes the InsertStatic method to be invoked.

  5. Confirm that a row has been added to the Departments table.

    SELECT * FROM Departments;

    The example program displays the updated contents of the Departments table in the database server messages window.

  6. There is a similar method in the example class called DeleteStatic that shows how to delete the row that has just been added. Call the JDBCExample.main method as follows:

    CALL JDBCExample( 'delete' );

    The argument string 'delete' causes the DeleteStatic method to be invoked.

  7. Confirm that the row has been deleted from the Departments table.

    SELECT * FROM Departments;

    The example program displays the updated contents of the Departments table in the database server messages window.

Results

Rows are inserted and deleted from a table using static SQL statements in a server-side JDBC application.