An example that shows query results

The following example implements a procedure called showusers(), which runs a query, retrieves all rows from the returned result, and prints the rows in the JVP log file:
import com.informix.udr.*;
import java.sql.*;

public class admin
{
   public static void showusers() throws SQLException
   {
      UDREnv env = UDRManager.getUDREnv();
      UDRLog log = env.getLog();
      String name = env.getName();

Connection conn = DriverManager.getConnection
         ("jdbc:informix-direct:");
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery
         ("SELECT * FROM Users");
      log.log("User information:");

      while ( rs.next() ) 
      {
         String UID = rs.getString(1);
         String Password = rs.getString(2);
         String Last = rs.getString(3);
         String First = rs.getString(4);
      
         // Write out the UDR name followed by the
         // columns values
         String line = name + " : " +
            UID + " " + Password + " " + Last + " " + First;
         log.log(line);
      }
      stmt.close();
      conn.close();
   }
}

After you create and install the JAR file that contains this Java method, the next task is to register the showusers() method as a UDR by giving it an SQL procedure signature. For the CREATE PROCEDURE statement that registers showusers(), see Specify the JVP.

The syntax for invoking a UDR written in Java code is no different from a standard UDR call, as follows:
EXECUTE PROCEDURE showusers()