aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/utils/CheckVersion.java
blob: b82ba335fd37c81135f131a45c7a73c6e4ee08fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package utils;

/**
 * This little app checks to see what version of JVM is being used.
 * It does this by checking first the java.vm.version property, and
 * if that fails, it looks for certain classes that should be present.
 */
public class CheckVersion
{
    /**
     * Check for the existence of a class by attempting to load it
     */
    public static boolean checkClass(String c) {
	try {
	    Class.forName(c);
	} catch(Exception e) {
	    return false;
	}
	return true;
    }
    
    /**
     * This first checks java.vm.version for 1.1, 1.2 or 1.3.
     *
     * It writes jdbc1 to stdout for the 1.1.x VM.
     *
     * For 1.2 or 1.3, it checks for the existence of the javax.sql.DataSource
     * interface, and if found writes enterprise to stdout. If the interface
     * is not found, it writes jdbc2 to stdout.
     *
     * PS: It also looks for the existence of java.lang.Byte which appeared in
     * JDK1.1.0 incase java.vm.version is not heeded by some JVM's.
     *
     * If it can't work it out, it writes huho to stdout.
     *
     * The make file uses the written results to determine which rule to run.
     *
     * Bugs: This needs thorough testing.
     */
    public static void main(String args[])
    {
	String vmversion = System.getProperty("java.vm.version");
	
	// We are running a 1.1 JVM
	if(vmversion.startsWith("1.1")) {
	    System.out.println("jdbc1");
	    System.exit(0);
	}
	
	// We are running a 1.2 or 1.3 JVM
	if(vmversion.startsWith("1.2") ||
	   vmversion.startsWith("1.3") ||
	   checkClass("java.lang.Byte")
	   ) {
	    
	    // Check to see if we have the standard extensions. If so, then
	    // we want the enterprise edition, otherwise the jdbc2 driver.
	    if(checkClass("javax.sql.DataSource"))
		System.out.println("enterprise");
	    else
		System.out.println("jdbc2");
	    System.exit(0);
	}
	
	System.out.println("huho");
	System.exit(0);
    }
}