Chapter 2. Installation

Index:

  1. System Requirements
  2. Setting the CLASSPATH
  3. Loading the Driver
  4. Connecting to the Database

System Requirements

HXTT DBF packages include a Type 4 JDBC driver. Type 4 indicates that the driver is written in Pure Java, and communicates in the database system's own network protocol. Because of this, the driver is platform independent; once compiled, the driver can be used on any system. HXTT DBF can run on any platforms with Java VM, which includes Microsoft Windows, Novell Netware, OS2, UNIX, and LINUX. HXTT DBF supports Personal Java, JDK1.0.X, JDK1.1.X, JDK1.2.X, JDK1.3.X, JDK1.4.X, JDK1.5.X, JDK1.6.X, JDK1.7.X, JDK1.8.X, and JDK1.9.X. HXTT DBF includes a database engine which can support multi-user access. It supports { UNION | INTERSECT | EXCEPT | MINUS } [ ALL ] query , INNER JOIN, FULL JOIN, LEFT JOIN, RIGHT JOIN, NATURAL JOIN, CROSS JOIN, and subquery which includes single-row subquery, multirow subquery, multiple-column subquery, inline views, and correlated subquery.

Setting the CLASSPATH

When java loads any class, it searches a list known as the classpath. This is a list of directories where classes are placed, or a list of jar files (archives containing classes and other resources) or both. HXTT DBF driver is a Type 4 driver. You can do this in many different methods, but the most command are:

  1. Setting the CLASSPATH environment variable.
  2. putting it on the command line using the -cp parameter.
  3. placing it in the JVM's lib/ext directory.
  4. extract all files in jar file into the directory of your application.

You can know detailed information about "Setting the Classpath" from your JDK Tools and Utilities. Let's use JDBC4.0 package as a simple sample. To put DBF_JDBC40.jar into your class path, you should use "export CLASSPATH=/usr/share/lib/DBF_JDBC40.jar:$CLASSPATH" on Solaris and Linux, and "SET CLASSPATH=\javalib\DBF_JDBC40.jar;%classpath%" on Windows.

Loading the Driver

Any source that uses JDBC needs to import the java.sql package by using " import java.sql.*;".

HXTT DBF driver' name is com.hxtt.sql.dbf.DBFDriver, and you can uses it without involving hard coding the driver into your code. You do this by setting the jdbc.drivers system property. For example, for command line apps you can use:
java -Djdbc.drivers=com.hxtt.sql.dbf.DBFDriver yourApp
Then, the JVM upon startup will load the drivers automatically. Some applications (JBoss, Tomcat etc) support a .properties file which they use to save putting this on the command line.

The second method is the most common and involves you loading the driver yourself. It's simple:
Class.forName("com.hxtt.sql.dbf.DBFDriver");
From then on you can get connections from DriverManager.
Note: If Class.forName() throws ClassNotFoundException, you should check your classpath.

Connecting to the Database

After the driver has been registered with the DriverManager, you can obtain a Connection instance that is connected to a particular database by calling DriverManager.getConnection(). With JDBC, a database is represented by a URL (Uniform Resource Locator).

        Embedded:
                jdbc:dbf:[//]/[DatabasePath][?prop1=value1[;prop2=value2]] (You can omit that "//" characters sometimes)
                        For example:
                                "jdbc:dbf:/."
                                "jdbc:dbf:/c:/data" for Windows driver
                                "jdbc:dbf:///c:/data" for Windows driver
                                "jdbc:dbf:////usr/data" for unix or linux
                                "jdbc:dbf://///192.168.10.2/sharedir" for UNC path
                                "jdbc:dbf:/./data"
        Remote Access (client/server mode):
                jdbc:dbf://host:port/[DatabasePath]
                        For example: "jdbc:dbf://domain.com:3099/c:/data" if one DBFServer is run on the 3099 port of domain.com
        Compressed Database:(.ZIP, .JAR, .GZ, .TAR, .BZ2, .TGZ, .TAR.GZ, .TAR.BZ2, .7z) 
                jdbc url format is the same as embedded url and remote url.
                        For example:
                                "jdbc:dbf:/c:/test/testdbf.zip
        Memory-only Database:
                jdbc:dbf:/_memory_/
        URL Database:(http protocol, https protocol, ftp protocol, sftp protocol)
                jdbc:dbf:http://httpURL
                jdbc:dbf:https://httpsURL
                jdbc:dbf:ftp://ftpURL
                jdbc:dbf:ftps://ftpURL
                jdbc:dbf:ftpes://ftpURL
                jdbc:dbf:sftp://sftpURL
                        For example:
                                "jdbc:dbf:http://www.hxtt.com/test" //Note: FTP site's user/password should be set in ftpURL, and cannot be set in JDBC connection property because user/password JDBC connection property belongs to server/client connection.
                                               //FTP  protocol supports  explicit SSL/TLS encryption (FTPES)  and  implicit SSL/TLS (FTPS). FTPES can be detected according to FTP Server reply, and FTPS can be used if you use port 990 in  Ftp url.
                                "jdbc:dbf:sftp://testa:123456@localhost"
        SAMBA Database:(smb protocol)
                                jdbc:dbf:smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?[param=value]]
                        For example:
                                "jdbc:dbf:smb://test1:123@100.100.13.94/dbffiles/zone" //Note: SAMBA user/password should be set in SMB url, and cannot be set in JDBC connection property because user/password JDBC connection property belongs to server/client connection.
	UNC path JDBC url:
                jdbc:dbf:/uncpath
                jdbc:dbf:///uncpath
                        For example:
                                "jdbc:dbf:/\\PC17\c$\values" 
                                "jdbc:dbf:/\\PC17\val"
	Free JDBC url:(Warning: only use it for special project)
                jdbc:dbf:/" or "jdbc:dbf:///". Then you can use some full UNC path names in SQL to visit anywhere where your Java VM has right to access.
                        For instance:
                                select * from \\amd2500\e$\dbffiles\test;
                                select * from "\\amd2500\d$\dbffiles".test;
                                select * from ".".test;

         HXTT DBF supports seamlessly data mining on memory-only table, physical table, url table, compressed table, SAMBA table in a sql. More details
         is in Advanced Programming chapter.

To connect, you need to get a Connection instance from JDBC. To do this, you use the DriverManager.getConnection() method:

Connection con = DriverManager.getConnection(url, properties);

There are a few different signatures for the getConnection() method. You should see the API documentation that comes with your JDK for more specific information on how to use them. You can specify additional properties to the JDBC driver by placing them in a java.util.Properties instance and passing that instance to the DriverManager when you connect.

Property Name
Definition
Default Value
lockType To specify a compatible lock for other applications. You can use DBASE, DBASE4BDE, DBASEIII, DBASEIV, CLIPPER, CLIPPER5.3, PowerPlus, Alaska, SoftC, DampSoft, DampSoftRead, FOXBASE, FOXBASE4UNIX, FOXPRO, FOXPRO4UNIX, FOXPRO4BDE, and VFP. null
deletesAreVisible Indicates whether DBF's resultSet includes deleted records. false
deletesAreBlank Indicates whether one destination data record will become one deleted blank record when delete it. false
DefaultExtension Indicates whether DBF driver uses another default extension to replace 'DBF'. DBF
DefaultCDXExtension Indicates whether DBF driver uses another default CDX extension to replace 'CDX'. CDX
DefaultMDXExtension Indicates whether DBF driver uses another default MDX extension to replace 'MDX'. MDX
DefaultNTXExtension Indicates whether DBF driver uses another default NTX extension to replace 'NTX'. NTX
DefaultNDXExtension Indicates whether DBF driver uses another default NDX extension to replace 'NDX'. NDX
DefaultIDXExtension Indicates whether DBF driver uses another default IDX extension to replace 'IDX'. IDX
OtherExtensions Indicates whether DBF driver supports other extensions except for 'DBF'. false
versionNumber Xbase Version Number. You can use null, "30"(Visual FoxPro 3.0~9.0), "02"(FoxBase, dBASE II), "03"(dBASE III, Clipper), "83", "04"(dBASE IV), "05"(dBASE V), "F5"(FoxPro),"8B", "8E", "7B", or "DB2K"(dbase 2000). This parameter is only used for CREATE TABLE. 30
blockSize Xbase's blockSize. You can use 1~255 64
missingMemoFile Indicates the action when memo file is missing. You can use "throw" (throw an SQLException), "ignore" (continue to load table when memo file is missing. All memo columns will return null value.), and "repair" (clear all old memo value, and rebuild a new memo file). throw
loadIndices Indicates whether load automatically and update index files. true
Default Index Suffix Indicates the default suffix for the index file. You can use null, "IDX","CDX","NDX","MDX", and "NTX" now. null
Incremental Index Indicates to support naming scheme for tablen.* (table0n.*, table00n.*) (n:1~9). You can use null, "IDX","CDX","NDX","MDX", and "NTX" now. For instance, you have a table P2FSACX.DBF which has indices of P2FSACX1.NTX and P2FSACX2.NTX, but you haven't a CGP file to load two index, you can set that property to NTX. null
COMPACTEDINDEX Indicates whether the default index file is compacted or not. true
collationSequence Collation sequence for Clipper International version. You can use null,"British","Danish","Dutch","Finnish","French","German", "Greek437","Greek851","Icelandic850","Icelandic861","Italian","Mazovia","Norwegian","Portuguese","Spanish", or "Swedish". null
tmpdir Indicates whether set a temp directory, Default: the value of JVM's "java.io.tmpdir" property. If that value is incorrect, using the directory of JDBC url. _memory_ means large data in memory. null
delayedClose Indicates the delayed seconds for close transaction. That option is used to avoid frequent close/open table operations for following sqls. Automatic temporary index is disabled when delayedClose<=60s. You can use 0~120 seconds. Default: 3. null
refreshInterval To specify a a refresh interval setting in seconds for FTP/SFTP/HTTP/HTTS database file which determines how long it to discard the content cache. 60
lockTimeout To specify HXTT DBF driver's timeout in milliseconds to wait until other processes or applications released record lock or table lock. 0 means a default value, and <0 means no wait. For server/client mode, remote client connection uses also that parameter(Default value: 30000ms) to wait response from server side. 1000
maxIdleTime Indicates the max idle time in minute for remote connection. That option is mainly used to avoid closing automatically idle remote connection for connection pool. Embedded idle connectoin won't be closed automatically except for garbage collection. You can use 1~1440 minutes. Default: 30. null
soTimeout To specify Enable/disable Socket read timeout with the specified timeout, in milliseconds. With this option set * to a non-zero timeout, a read() call on the InputStream associated with * this Socket will block for only this amount of time. If the timeout * expires, a java.net.SocketTimeoutException is raised, though the * Socket is still valid. The option must be enabled * prior to entering the blocking operation to have effect. The * timeout must be {@code > 0}. * A timeout of zero is interpreted as an infinite timeout. 1000
charSet To specify a Character Encoding Scheme other than the client default. You can find a Supported Encodings list of file:///c|/jdk1.2/docs/guide/internat/encoding.doc.html. Cp895(Czech MS - DOS 895), Cp620(Polish MS - DOS 620) and Mazovia are extra supported although JVM doesn't support those. null
ignoreCompressionFile Indicates whether can list alll tables in compression file. You can use null, true, false true
ODBCTrimBehavior Indicates whether works like MS Access ODBC driver to ignore tail space characters in condition expression. You can use null, true, false false
caseInsensitive Indicates whether works like MS Access ODBC driver to be case insensitve for string comparison. You can use null, true, false false
emptyDecimalAsZero Indicates whether returns empty decimal as zero value. You can use null, true, false false
emptyStringAsNull Indicates whether returns empty string as null value. You can use null, true, false true
locale locale is used to specify a default local for parse. You can use CANADA, CANADA_FRENCH, CHINA, CHINESE, ENGLISH, FRANCE, FRENCH, GERMAN, GERMANY, ITALIAN, ITALY, JAPAN, JAPANESE, KOREA, KOREAN, PRC, ROOT, SIMPLIFIED_CHINESE, TAIWAN, TRADITIONAL_CHINESE, UK, or US. null
dateFormat dateFormat is used to specify a default parse sequence of date(Default: 'yyyy-MM-dd') format. Date and Time patterns follow the Java java.text.SimpleDateFormat Format (https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) standard. You can use __or__ to define more than one format for ETL data type detection, but only the first format will be used for output format. yyyy-MM-dd
timeFormat timeFormat is used to specify a default parse sequence of time(Default: 'hh:mm:ss') format. Date and Time patterns follow the Java java.text.SimpleDateFormat Format (https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) standard. You can use __or__ to define more than one format for ETL data type detection, but only the first format will be used for output format. hh:mm:ss
timestampFormat timestampFormat is used to specify a default parse sequence of timestamp(Default: 'yyyy-MM-dd hh:mm:ss') format. Date and Time patterns follow the Java java.text.SimpleDateFormat Format (https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) standard. You can use __or__ to define more than one format for ETL data type detection, but only the first format will be used for output format. yyyy-MM-dd hh:mm:ss
decimalFormat decimalFormat is used to specify a default parse sequence of decimal number format. You can use __or__ to define more than one format for ETL data type detection, but only the first format will be used for output format. null
decimalSeparator decimalSeparator is used to specify a default character for decimal sign. Different for French, etc. null
groupingSeparator groupingSeparator is used to specify a default character for thousands separator. Different for French, etc. null
timezone local is used to specify a default time zone for calendar. "local" means use the local calendar. null
focusValue For extracting XML/JSON data into a relational table, if set to true, it will fetch parsed SQL value, not XML element, or JSON object. true
stuffAutomatically For extracting XML/JSON data into a relational table, if it set to true, it can split one complicated element/object into multi data rows. If it set to false, it can still flat XML/JSON into SQL table, but won't increase data rows by stuff automatically. true
maxStuffColumnCount When using stuffAutomatically=true, maxStuffColumnCount value limits the max expanded child columns. Please remember, one stuffed column can own many child columns. 2
maxStuffLevel maxStuffLevel value limits the max level of expanded child columns. For instance, `SubImageList/SubImageInfoObject/ImageID` column will show for maxStuffLevel=3. `SubImageList/SubImageInfoObject/` column will show for maxStuffLevel=2, and you can use `SubImageList/SubImageInfoObject/`->'ImageID' to quote the value of ImageID. 2
hyphen4name For Extracting XML/JSON data into a relational table, it can convert automatically sub element/object to SQL column. The default column name is ParentName_ChildName, if you use '_' as separator. For instance, ""name": {"first": "John", "last": "Doe" } will become two columns, name_first and name_last. If you use null or empty string, then the columm name will become ParentNameChildName. Then you can use select namefirst,namelast from yourJsonTable. _
hyphenInColumName '_', '-', and ' '(space) can occur in column name, and you can choose hyphenInColumName=_(or other strings) to format those special characters(_,-, space) so that database tools can read it. null
maxCacheSize Indicates the max memory utilization for per table on automatic temporary index or matched result cache. You can use 16~65536 kilo bytes. Default: 1024. null
host The remote host on which one DBFServer is running null
port The port on which one DBFServer is listening null
serverType The type of DBFServer on the remote host null
user The user to connect as null
password The password to use when connecting null
cryptType To specify a crypt type for Table Encryption and Column Level Encryption. All new created table in this connection will become crypted table. You can use DES, TRIDES, BLOWFISH, and AES now. null
cryptKey To specify a crypt key. Without encrypt key, CREATE TABLE won't create crypted table. null
storeCryptKey Indicates whether crypt key is stored in crypted table. If stored, crypted table can be opened automatically in any connection without predefined crypt properites. If not stored, cryptd table can only be opened with correct key, and none include us can help you in cracking your data without the correct key. false

When your code then tries to open a Connection, and you get a No driver available SQLException being thrown, this is probably caused by the driver not being in the class path, or the JDBC url not being correct.

To close the database connection, simply call the close() method to the Connection:

con.close();

 

Copyright © 2003-2019 Heng Xing Tian Tai Lab | All Rights Reserved. |