Use HSQLDB to consolidate common databases into applications

Source: Internet
Author: User
Program | data | Databases use HSQLDB to integrate common databases into applications   in http://blog.csdn.net/lizongbo/archive/2005/02/13/286697.aspx  Some common databases are mentioned, which can be treated as fixed-coded databases. For these stacks, queries are usually used only.   Therefore for some such as users want to only pass the IP address to query the user information, or only to the administrative division number, you can get the administrative division name and so on demand. And users do not want to configure database information, and so on, access files, although more convenient, but does not have cross-platform effect, so you can use open source free Hsql for the application of small database embedding. In particular, the 1.7.2 version adds new features that enable you to access the database directly in the jar in a read-only manner. Therefore, packaging good class and data files packaged together, can be very convenient for others to use.   Below is the operation process, first download hsql, the latest stable version is 1.7.3.3:http://heanet.dl.sourceforge.net/sourceforge/hsqldb/hsqldb_1_7_3_3.zip   Download IP database:http://96hk.y365.com/soft/qqwry.rar  and then use their own tools to extract their data into a text file, open with EditPlus, replace   cz88.net, To reduce the footprint of the file (using regular expressions to replace them, and to make the data regular.) Convert to XML with XMLSpy and import access, which can be omitted completely, and then import the 195,074 records directly with access.   Then import data from access such as my usual data have IP address Information table, administrative divisions and Provincial letter table:  //CREATE TABLE     connto.createstatement (). Execute ( "CREATE TABLE Province (Pdomain VARCHAR (3), Plabel VARCHAR (), PName VARCHAR (6), PNO VARCHAR (3), Pshortname VARCHAR (2))" ;    connto.createstatement (). Execute (        CREA)TE TABLE Xzqh (NAME VARCHAR, CODE VARCHAR (6), O_code VARCHAR (8)) ";    connto.createstatement (). Execute (        "CREATE TABLE ipinfo (IPS bigint,ipe bigint,area VARCHAR (60))");     ResultSet rs = stmtin.executequery ("Select * from Province");   preparedstatement pstmt = Connto.preparestatement (        insert into province (Pdomain,plabel,pname,pno) , Pshortname) VALUES (?,?,?,?,?) ");   After the import is complete, add the data file to the jar file and encapsulate the usual methods. On it, the future of data maintenance is also very simple, as long as the results do not modify the table, just to update the data file, do not need to modify any code.   Calling Method Example: first introduce the jar file, then use the following method call, String Area=com.lizongbo.database.searchutil.findareabyip ("192.168.9.1");   Users do not need to care about anything else, one line of code will get the desired results.    However, it should be noted that after using the IP database, because of the large number of IP database records, the generated scrpit file is larger, my file has 22M, packaging compressed jar, also has 3M size, initialization database will be very slow. Overall, sacrificing space and some memory in exchange for application reusability and Cross-platform and data-logging maintainability is worth it.   Drawing:     reference:  http://hsqldb.sourceforge.net  http://hsqldb.sourceforge.net/web/ hsqlfaq.html http://www-900.ibm.com/developerworks/cn/java/l-hsqldb/index.shtml 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.