// -------------------------------------------------------------------- // Very simple SQLJ sample program to select records from a database // Frank Naude - Oct 2000 // -------------------------------------------------------------------- import sqlj.runtime.*; import sqlj.runtime.ref.*; import java.sql.*; public class SQLJTst1 { public static void main(String[] args) { Connection c = null; String dbURL = "jdbc:oracle:thin:@oracle10:1521:acme"; String userid = "acme"; String passwd = "acme"; try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); c = DriverManager.getConnection(dbURL, 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)); // Select a sinngle row from the database String dBuser; #sql { select user into :dBuser from dual }; System.out.println("Database username is " + dBuser); // Close the database connection #sql { rollback work }; c.close(); System.out.println("Disconected..."); } catch (SQLException e) { e.printStackTrace(); } } }