// -------------------------------------------------------------------- // Example SQLJ program to execute DML against the database // Frank Naude - Oct 2000 // -------------------------------------------------------------------- import sqlj.runtime.*; import sqlj.runtime.ref.*; import java.sql.*; public class SQLJTst5 { public static void main(String[] args) { Connection c = null; String URL = "jdbc:oracle:thin:@oracle10:1521:acme"; String userid = "acme"; String passwd = "acme"; try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); c = DriverManager.getConnection(URL, userid, passwd); System.out.println("Successfully conencted to Oracle..."); // You need to set a Context for SQLJ, otherwise - // SQLException: found null connection context DefaultContext.setDefaultContext( new DefaultContext(c)); // DML against the database... #sql { insert into x values (sysdate) }; System.out.println("Row inserted!!!"); #sql { update x set a = sysdate }; #sql { delete from x where trunc(a) = trunc(sysdate) }; // Close the database connection #sql { commit work }; // #sql { rollback work }; c.close(); System.out.println("Disconected..."); } catch (SQLException e) { e.printStackTrace(); } } }