home *** CD-ROM | disk | FTP | other *** search
/ Enter 1999 September / ENTER9_2.bin / prog_8 / jbuilder3 / TRIAL / INTRCLNT / DATA.Z / DataSourceExample.java < prev    next >
Encoding:
Java Source  |  1999-01-18  |  2.2 KB  |  54 lines

  1. // Copyright InterBase Software Corporation, 1998.
  2. // Written by com.inprise.interbase.interclient.r&d.PaulOstler :-)
  3. //
  4. // An example of using a JDBC 2 Standard Extension DataSource.
  5. // The DataSource facility provides an alternative to the JDBC DriverManager,
  6. // essentially duplicating all of the driver managerÆs useful functionality.
  7. // Although, both mechanisms may be used by the same application if desired,
  8. // JavaSoft encourages developers to regard the DriverManager as a legacy
  9. // feature of the JDBC API.
  10. // Applications should use the DataSource API whenever possible.
  11. // A JDBC implementation that is accessed via the DataSource API is not
  12. // automatically registered with the DriverManager.
  13. // The DriverManager, Driver, and DriverPropertyInfo interfaces
  14. // may be deprecated in the future.
  15.  
  16. public final class DataSourceExample
  17. {
  18.   static public void main (String args[])
  19.   {
  20.     // Create an InterClient data source bean manually;
  21.     // beans are normally manipulated by a GUI tool.
  22.     // Bean properties are always set using the setXXX signature.
  23.     interbase.interclient.DataSource dataSource = new interbase.interclient.DataSource ();
  24.  
  25.     // Set the standard properties
  26.     dataSource.setServerName ("perdy");
  27.     dataSource.setDatabaseName ("d:/databases/employee.gdb");
  28.     dataSource.setDataSourceName ("Employee");
  29.     dataSource.setDescription ("An example database of employees");
  30.     dataSource.setPortNumber (3060);
  31.     dataSource.setNetworkProtocol ("jdbc:interbase:");
  32.     dataSource.setRoleName (null);
  33.     
  34.     // Set the non-standard properties
  35.     dataSource.setCharSet (interbase.interclient.CharacterEncodings.NONE);
  36.     dataSource.setSuggestedCachePages (0);
  37.     dataSource.setSweepOnConnect (false);
  38.  
  39.     // Connect to the InterClient DataSource
  40.     try {
  41.       dataSource.setLoginTimeout (10);
  42.       java.sql.Connection c = dataSource.getConnection ("sysdba", "masterkey");
  43.       // At this point, there is no implicit driver instance
  44.       // registered with the driver manager!
  45.       System.out.println ("got connection");
  46.       c.close ();
  47.     }
  48.     catch (java.sql.SQLException e) {
  49.       System.out.println ("sql exception: " + e.getMessage ());
  50.     }
  51.   }
  52. }
  53.               
  54.