Problem: This article provides a code example using SQL Roles with InterClient Solution: The information in this article applies to: * InterBase v5.x * InterClient v1.51 Note: You must have InterClient 1.51 or later to use SQL Roles. The following example demonstrates the use of SQL Roles with InterClient. The short explanation is to add roleName and its value to the property object that is passed to the getConnection method of the DriverManager class. ------------------------------- begin roles example ----------------------------------- import java.sql.*; import java.util.Properties; public class roles { Connection conn; public roles() { try { doDatabase(); } catch(SQLException sqlE) { System.out.println(sqlE.getMessage()); System.exit(1); } catch(ClassNotFoundException cnfE) { System.out.println(cnfE.getMessage()); System.exit(1); } } public void doDatabase() throws SQLException, ClassNotFoundException { // load the InterClient driver Class.forName("interbase.interclient.Driver"); // create Properties object to hold user, password, role Properties props = new Properties(); props.put("user", "testuser"); props.put("password", "testuser"); props.put("roleName", "testrole"); // make connection to database conn = DriverManager.getConnection("jdbc:interbase://localhost/d:/work/employee.gdb", props); // create statement Statement stmt = conn.createStatement(); // execute statement ResultSet rs = stmt.executeQuery("select foo_id from foobar"); // get results while(rs.next()) { System.out.println("Foo ID: " + rs.getInt(1)); } // close result set, statement, and connection rs.close(); stmt.close(); conn.close(); } public static void main(String args[]) { roles roleclass = new roles(); } }
Last Modified: 20-OCT-00