Loading ...
Sorry, an error occurred while loading the content.

server vesion

Expand Messages
  • hugo.larson
    Hello, Is there a way to determine which version of Firebird is running before connection to a Database using pure JDBC? I m looking in
    Message 1 of 2 , Feb 3, 2013
    • 0 Attachment
      Hello,

      Is there a way to determine which version of Firebird is running before
      connection to a Database using pure JDBC?

      I'm looking in org.firebirdsql.management but cant find anything fitting.

      I'm currently using FB 1.5 and Jaybird 2.1.6.

      Thanks,
      Hugo
    • Mark Rotteveel
      ... There currently is no default way to get it in Jaybird (without actually connecting to the database), but with the following code you can get the server
      Message 2 of 2 , Feb 3, 2013
      • 0 Attachment
        On 3-2-2013 13:34, hugo.larson wrote:
        > Hello,
        >
        > Is there a way to determine which version of Firebird is running before
        > connection to a Database using pure JDBC?
        >
        > I'm looking in org.firebirdsql.management but cant find anything fitting.
        >
        > I'm currently using FB 1.5 and Jaybird 2.1.6.

        There currently is no default way to get it in Jaybird (without actually
        connecting to the database), but with the following code you can get the
        server version without a reference to the database.

        GDSType gdsType = FBTestProperties.getGdsType();
        FBServiceManager fbServiceManager = new FBServiceManager(gdsType);
        fbServiceManager.setHost(FBTestProperties.DB_SERVER_URL);
        fbServiceManager.setPort(FBTestProperties.DB_SERVER_PORT);
        fbServiceManager.setUser(FBTestProperties.DB_USER);
        fbServiceManager.setPassword(FBTestProperties.DB_PASSWORD);

        GDS gds = GDSFactory.getGDSForType(gdsType);
        ServiceRequestBuffer srb =
        gds.createServiceRequestBuffer(ISCConstants.isc_info_svc_server_version);
        IscSvcHandle svcHandle = fbServiceManager.attachServiceManager(gds);
        byte[] buffer = new byte[1024];
        gds.iscServiceQuery(svcHandle, null, srb, buffer);

        // Now buffer[0] == ISCConstants.isc_info_svc_server_version
        // server_version is a string, so get 2 byte length from position 1
        int length = gds.iscVaxInteger(buffer, 1, 2);

        // Get string from buffer position 3 for length
        String serverVersion = new String(buffer, 3, length,
        StandardCharsets.ISO_8859_1);
        System.out.println(serverVersion);

        gds.iscServiceDetach(svcHandle);

        Output on my system is:
        WI-V2.5.2.26539 Firebird 2.5

        In Jaybird 2.2 you can then use the class
        org.firebirdsql.gds.impl.GDSServerVersion to parse the version:

        GDSServerVersion versionInfo =
        GDSServerVersion.parseRawVersion(serverVersion);

        This object gives you access to the various parts of the version (eg
        major (=2), minor (=5), variant (=2), build (=26539)).

        This code is Java 7 because of the use of
        java.nio.charset.StandardCharsets class, for earlier Java versions you
        need to use the character set name (string).

        Note that I only use the FBServiceManager class to simplify attaching to
        the servicemanager, you don't actually need it if you do all the
        plumbing that the ServiceManager does here.

        You will need to replace the FBTestProperties references with your own
        information (for getting the GDSType, use GDSType.getType("PURE_JAVA")
        (or "NATIVE" or "EMBEDDED").

        Mark
        --
        Mark Rotteveel
      Your message has been successfully submitted and would be delivered to recipients shortly.