Commits

Mort Yao committed 1ec938d

Jun 9: last update

  • Participants
  • Parent commits 4991f2c

Comments (0)

Files changed (3)

 <?xml version="1.0"?>
-<project name="jvisitor" default="compile-run" basedir=".">
+<project name="jvisitor" default="demo" basedir=".">
     <description>
         jvisitor
     </description>
         </java>
     </target>
     
-    <target name="compile-run" depends="compile">
+    <target name="demo" depends="compile">
         <java classpath="bin:lib/h2-1.3.167.jar" classname="db.Demo" fork="true">
         </java>
     </target>

src/db/Database.java

             Class.forName("org.h2.Driver");
             
             connection = DriverManager.getConnection(
-                "jdbc:h2:" +
-                "./db/jvisitor",
+                "jdbc:h2:db/" +
+                "jvisitor",
                 "",
                 "");
             
             Class.forName("org.h2.Driver");
             
             connection = DriverManager.getConnection(
-                "jdbc:h2:" +
+                "jdbc:h2:db/" +
                 databaseName +
                 ";CIPHER=AES",
                 loginName,
             Class.forName("org.h2.Driver");
             
             connection = DriverManager.getConnection(
-                "jdbc:h2:" +
+                "jdbc:h2:db/" +
                 databaseName +
                 ";CIPHER=AES",
                 loginName,
             Class.forName("org.h2.Driver");
             
             connection = DriverManager.getConnection(
-                "jdbc:h2:" +
+                "jdbc:h2:db/" +
                 databaseName +
                 (fileEncryption == "AES" || fileEncryption == "XTEA" ?
                     (";CIPHER=" + fileEncryption) :
             Class.forName("org.h2.Driver");
             
             connection = DriverManager.getConnection(
-                "jdbc:h2:" +
+                "jdbc:h2:db/" +
                 databaseName +
                 (fileEncryption == "AES" || fileEncryption == "XTEA" ?
                     (";CIPHER=" + fileEncryption) :
     }
     
     /**
+     * Returns the name of the current database.
+     * 
+     * @return Name of the current database
+     */
+    public String getName() throws SQLException {
+        
+        String result = "";
+        
+        PreparedStatement ps = connection.prepareStatement("CALL DATABASE()");
+        
+        try {
+            
+            ResultSet rs = ps.executeQuery();
+            
+            try {
+                
+                rs.next();
+                result = rs.getString(1);
+                
+            } finally {
+                
+                try {
+                    
+                    rs.close();
+                    
+                } catch (Throwable ignore) {
+                    
+                    // ignore
+                    
+                }
+            }
+            
+        } finally {
+            
+            try {
+                
+                ps.close();
+                
+            } catch (Throwable ignore) {
+                
+                // ignore
+                
+            }
+            
+        }
+        
+        return result;
+        
+    }
+    
+    /**
+     * Returns the path of the current database.
+     * 
+     * @return Path of the current database
+     */
+    public String getPath() throws SQLException {
+        
+        String result = "";
+        
+        PreparedStatement ps = connection.prepareStatement("CALL DATABASE_PATH()");
+        
+        try {
+            
+            ResultSet rs = ps.executeQuery();
+            
+            try {
+                
+                rs.next();
+                result = rs.getString(1);
+                
+            } finally {
+                
+                try {
+                    
+                    rs.close();
+                    
+                } catch (Throwable ignore) {
+                    
+                    // ignore
+                    
+                }
+            }
+            
+        } finally {
+            
+            try {
+                
+                ps.close();
+                
+            } catch (Throwable ignore) {
+                
+                // ignore
+                
+            }
+            
+        }
+        
+        return result;
+        
+    }
+    
+    /**
      * Returns the size of the cache in KB for the current database.
      * 
      * @return Size of the cache in KB
     
     public static void main(String[] args) throws Exception {
         
-        // Start the database connection. (deprecated)
-        /*
-        Database db = new Database("db/jvisitor", "sa", "group 12");
-        */
-        
         // Start the database connection.
-        Database db = new Database("db/jvisitor", "sa", "12", "group");
+        Database db = new Database("demo", "sa", "12", "group");
         
         // Get current settings.
         System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>");
+        System.out.println("DATABASE_NAME: " + db.getName());
+        System.out.println("DATABASE_PATH: " + db.getPath());
         System.out.println("CACHE_SIZE: " + db.getCacheSize());
         System.out.println("LOG: " + db.getLog());
         System.out.println("MULTI_THREADED: " + db.getMultiThreaded());
         db.setPassword("123456");
         
         // Close the existing database connection and restart a new connection.
-        db = new Database("db/jvisitor", "sa", "123456", "group", "AES", "FILE", true, 8192, 1, 1, 10000);
+        db = new Database("demo", "sa", "123456", "group", "AES", "FILE", true, 8192, 1, 1, 10000);
         
         // Get current settings.
         System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>");
+        System.out.println("DATABASE_NAME: " + db.getName());
+        System.out.println("DATABASE_PATH: " + db.getPath());
         System.out.println("CACHE_SIZE: " + db.getCacheSize());
         System.out.println("LOG: " + db.getLog());
         System.out.println("MULTI_THREADED: " + db.getMultiThreaded());