CN102521408A - Method for accessing flat file by using java database connectivity (JDBC) interface - Google Patents

Method for accessing flat file by using java database connectivity (JDBC) interface Download PDF

Info

Publication number
CN102521408A
CN102521408A CN2011104451270A CN201110445127A CN102521408A CN 102521408 A CN102521408 A CN 102521408A CN 2011104451270 A CN2011104451270 A CN 2011104451270A CN 201110445127 A CN201110445127 A CN 201110445127A CN 102521408 A CN102521408 A CN 102521408A
Authority
CN
China
Prior art keywords
file
result set
flat file
row
statement
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2011104451270A
Other languages
Chinese (zh)
Other versions
CN102521408B (en
Inventor
李品新
白芸
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingbase Information Technologies Co Ltd
Original Assignee
Beijing Kingbase Information Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Kingbase Information Technologies Co Ltd filed Critical Beijing Kingbase Information Technologies Co Ltd
Priority to CN201110445127.0A priority Critical patent/CN102521408B/en
Publication of CN102521408A publication Critical patent/CN102521408A/en
Application granted granted Critical
Publication of CN102521408B publication Critical patent/CN102521408B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention discloses a method for accessing a flat file by using a java database connectivity (JDBC) interface. The method comprises the following steps of: (1) establishing connection with the flat file by using a Connection object; (2) executing any of the operation of acquiring meta-information by using a DatabaseMetadata object, creating a PreparedStatement object for preprocessing and creating a Statement object for executing a structured query language (SQL) statement; (3) after the meta-information is acquired by the DatabaseMetadata object, returning a result set; and (4) executing the SQL statement by using the Statement object or the PreparedStatement object to operate the result set. By the method, an application developer can access the flat file through the JDBC standard interface like accessing a relational database, and an effective resolution is provided for data migration and data synchronization between the database and the flat file.

Description

A kind of method through JDBC interface accessing flat file
Technical field
The present invention relates to a kind of method of visiting flat file, relate in particular to a kind of method, belong to the database application technical field through JDBC (connection of Java database) interface accessing flat file.
Background technology
Flat file is meant removes all application-specific (program) form, uses the e-file of handling thereby make data element can move to other.Typical flat file comprises the e-file of forms such as txt, xls, csv.This data storage method of removing the application-specific form can avoid causing because of hardware and proprietary software out-of-date loss of data.
On the other hand, JDBC is the standard interface of Java language accessing database.Class and interface that it is write by one group of Java language are formed, and use embedded SQL statement, mainly realize the function of three aspects: foundation is connected with database, carries out SQL statement and treatment S QL statement execution result.JDBC is API for java applet person, as far as realizing that the service provider who is connected with database is an interface model.As API, JDBC is the interface that program development provides standard, and is that database manufacturer and third party's middleware manufacturer realize with being connected of database standard method being provided.
The JDBC interface uses existing SQL standard and supports the standard that is connected with other database, like the bridge joint between the ODBC (Open Database Connection).Through the JDBC interface, can be directly the bottom relational database be carried out SQL statement, obtains result set, Updated Information etc.Utilize the JDBC interface can make up more senior instrument and interface, make the database development personnel write various database applications by enough JavaAPI.
Fig. 1 has shown the fundamental mechanism through JDBC interface accessing relational database.Java application is the JDBC interface that provides of access relational databases manufacturer at first, and then visits corresponding relational database.The JDBC interface has been arranged, and sending SQL statement to various relational databases is exactly a thing easily.The application developer only need write a program with JDBC API, just can send the SQL call statement to corresponding database, and need not write corresponding application for every kind of database.
But for flat file, because not within the relational database category, operating system manufacturer does not provide the interface of various programming languages to realize, like the realization of JDBC or ODBC interface.Therefore, the application access flat file can only carry out through the mode of byte stream.Because problems such as operating system difference, document No. difference, file structure difference can cause a large amount of coding works, for application program is write the unnecessary difficulty of increase.
Summary of the invention
Technical matters to be solved by this invention is to provide a kind of method through JDBC interface accessing flat file.This method can make application program pass through JDBC interface accessing flat file as access relational databases.
For realizing above-mentioned goal of the invention, the present invention adopts following technical scheme:
A kind of method through JDBC interface accessing flat file is characterized in that comprising the steps:
(1) connects through Connection object and flat file;
(2) any in the following operation of execution: through DatabaseMetadata object acquisition metamessage; Establishment is used for pretreated PreparedStatement object; Establishment is used to carry out the Statement object of SQL statement;
(3) after passing through DatabaseMetadata object acquisition metamessage, the return results collection;
(4) carrying out SQL statement through said Statement object or said PreparedStatement object operates said result set.
Wherein more excellently, the attribute through appointment in the URL that connects string determines following information in the said step (1): whether the path of document storage, document No. form, line Separator, Column Cata Format, text qualifier and file header represent the row name.
Wherein more excellently, in the said step (3), the mode of obtaining metamessage comprises result set that obtains table and the result set that obtains row.
The result set that obtains table is meant according to the file path of appointment in link information and the filtercondition of appointment in this interface method; Return the file that all satisfy condition with the mode of result set; Each file is represented a table, in result set, representes with a record.
The result set that obtains row is meant according to document No. form, line Separator, Column Cata Format, text qualifier and the file header of appointment in connecting string whether represent the row name; With all row in the mode backspace file of result set; Row of every record expression comprise row name, row type in the return message.
The present invention carries out the flat file read-write for application developer through java application provides convenience.Utilize the present invention, application developer can be as access relational databases through JDBC standard interface visit flat file, for the data migtation between database and the flat file and data sync provide an effective solution.
Description of drawings
Below in conjunction with accompanying drawing and embodiment the present invention is done further detailed description.
Fig. 1 is in the prior art, and java application is through the schematic diagram of mechanism of JDBC interface accessing relational database;
Fig. 2 is the operating process synoptic diagram through way access flat file provided by the present invention;
Fig. 3 is among the present invention, and java application is through the schematic diagram of mechanism of the flat file of JDBC interface accessing tape format.
Embodiment
In one embodiment of the invention; Actual demand according to the application access flat file; Realize following object through programming: (a) be used to carry out the Connection object that relational database connects, can specify the information such as position, extension name, form, coding of the flat file that will read and write through this object based on the JDBC interface; (b) be used to obtain the DatabaseMetadata object of database metamessage, can obtain about metamessages such as table, row, types through this object; (c) be used to carry out the Statement object of SQL statement, through carrying out establishment, deletion, the structure change that DDL (DDL) statement carries out file, change through carrying out the additions and deletions that DML (DML) statement carries out file content; (d) be used to carry out the PreparedStatement object of preprocessor statement,, realize batch updating data in the database through Wire Parameters; (e) be used to deposit the ResultSet object of result set, with the form of result set, metamessage perhaps in the backspace file; (f) be used for the associated class of syntax parsing.Above-mentioned object with type concrete realization be the routine techniques means that those of ordinary skills can both grasp, this with regard to not quite clear describe in detail clear.
As shown in Figure 2; Application program is utilized above-mentioned object and class based on the JDBC interface, connects, obtains metamessage, query results through comprising, result set is operated, realized the accessing operations such as read-write to flat file through operation stepss such as result set updating files.Specify as follows:
At first, application program connects through Connection object and flat file.In the process that connects, can decide the following attribute information of file: the path of document storage, document No. form, in order to the separator (line Separator) of distinguishing every data, in order to the separator (Column Cata Format) of distinguishing each attribute, whether represent row name etc. in order to separator (text qualifier), the file header of handling the text field through the attribute of appointment among the url (URL) that connects string.Information such as the position of file, extension name, form, coding can directly be specified through connecting string.
After connecting; The operation of several class objects below can carrying out as required: through DatabaseMetadata object acquisition metamessage; Establishment is used for pretreated PreparedStatement object, creates the Statement object that is used to carry out SQL statement.Wherein mainly to be used in the flat file be the occasion of target source to the DatabaseMetadata object, and PreparedStatement object and Statement object mainly to be used in the flat file be the occasion of data source.
For flat file, the mode of obtaining metamessage mainly contains result set that obtains table and the result set that obtains row.Obtain the result set of table (getTables); Be meant according to the file path of appointment in link information and the filtercondition of appointment in this interface method; Mode with result set (ResultSet) is returned the file that all satisfy condition; Each file is represented a table, in result set, representes with a record.Obtain the result set of row (getColumns); Be meant according to document No. form, line Separator, Column Cata Format, text qualifier and the file header of appointment in connecting string and whether represent row name etc.; With all row in the mode backspace file of result set (ResultSet); Row of every record expression comprise row name, row type etc. in the return message.
In the present invention, carrying out the function that SQL statement operates result set realizes through creating Statement object or PreparedStatement object.For DDL (DDL) statement and simple SQL statement, the execute method that can directly call in the Statement object is carried out, as creating table and delete list.For creating the predicative sentence; At first call syntax Analysis Module; Parse table name, row name in the SQL statement, according to the document No. form of the appointment in table name and the connection attribute, the filename and the form of file created in decision; Whether represent row name, Column Cata Format, line Separator, the content that decision writes according to the file header of appointment in the connection attribute in file again.For the delete list statement, at first call syntax Analysis Module, parse the table name in the SQL statement, find corresponding file name, deleted file according to table name again.For simple DML (DML) statement; Like the Select statement, at first call syntax Analysis Module, parse table name and row name in the SQL statement; Find the corresponding file name according to table name; According to document No. form, line Separator, the Column Cata Format of appointment in row name and the connection attribute, the traversal file returns qualified value with the mode of result set.
Insert and the batch updating operation for batch, can realize through the correlation technique that provides in the PreparedStatement object based on result set.Specify as follows: at first through a pre-service SQL statement; State a PreparedStatement object, call syntax Analysis Module, resolve table name, row name and placeholder in the pre-service SQL statement; According to placeholder information, the array of structure storage batch updating value.In calling the process of binding parameter, will put into the relevant position of array corresponding to the analog value of placeholder.When submitting in batches, find the corresponding file name according to table name, according to document No. form, line Separator, the Column Cata Format of appointment in the connection attribute; Decision writes the form of file content; At last, the traversal array writes all records of batch updating in the file.
As shown in Figure 3, java application can use the flat file of JDBC standard interface visit tape format as access relational databases.For the application developer, the mechanism of application access flat file and access relational databases machine-processed just the same, the interface that the application developer was concerned about is same standard interface, is exactly the JDBC interface.
Through flat file access method provided by the present invention, the application developer be can significantly reduce and relational database and the mutual difficulty of flat file realized, reduce the coding work amount, practice thrift cost of development, improve the maintainability and the extensibility of system.Particularly aspect the data migtation and data sync of dealing with relationship between database and the flat file, use same set of coding, both can access relational databases, can read and write flat file again.
More than the method through JDBC interface accessing flat file provided by the present invention has been carried out detailed explanation.To those skilled in the art, any conspicuous change of under the prerequisite that does not deviate from connotation of the present invention, it being done all will constitute to infringement of patent right of the present invention, with corresponding legal responsibilities.

Claims (5)

1. the method through JDBC interface accessing flat file is characterized in that comprising the steps:
(1) connects through Connection object and flat file;
(2) any in the following operation of execution: through DatabaseMetadata object acquisition metamessage; Establishment is used for pretreated PreparedStatement object; Establishment is used to carry out the Statement object of SQL statement;
(3) after passing through DatabaseMetadata object acquisition metamessage, the return results collection;
(4) carrying out SQL statement through said Statement object or said PreparedStatement object operates said result set.
2. the method through JDBC interface accessing flat file as claimed in claim 1 is characterized in that:
In the said step (1), determine following information through the attribute that connects appointment in the URL of going here and there: whether the path of document storage, document No. form, line Separator, Column Cata Format, text qualifier and file header represent the row name.
3. the method through JDBC interface accessing flat file as claimed in claim 1 is characterized in that:
In the said step (3), the mode of obtaining metamessage comprises result set that obtains table and the result set that obtains row.
4. the method through JDBC interface accessing flat file as claimed in claim 3 is characterized in that:
The result set that obtains table is meant according to the file path of appointment in link information and the filtercondition of appointment in this interface method; Return the file that all satisfy condition with the mode of result set; Each file is represented a table, in result set, representes with a record.
5. the method through JDBC interface accessing flat file as claimed in claim 3 is characterized in that:
The result set that obtains row is meant according to document No. form, line Separator, Column Cata Format, text qualifier and the file header of appointment in connecting string whether represent the row name; With all row in the mode backspace file of result set; Row of every record expression comprise row name, row type in the return message.
CN201110445127.0A 2011-12-27 2011-12-27 Method for accessing flat file by using java database connectivity (JDBC) interface Active CN102521408B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110445127.0A CN102521408B (en) 2011-12-27 2011-12-27 Method for accessing flat file by using java database connectivity (JDBC) interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110445127.0A CN102521408B (en) 2011-12-27 2011-12-27 Method for accessing flat file by using java database connectivity (JDBC) interface

Publications (2)

Publication Number Publication Date
CN102521408A true CN102521408A (en) 2012-06-27
CN102521408B CN102521408B (en) 2015-04-08

Family

ID=46292321

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110445127.0A Active CN102521408B (en) 2011-12-27 2011-12-27 Method for accessing flat file by using java database connectivity (JDBC) interface

Country Status (1)

Country Link
CN (1) CN102521408B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103345420A (en) * 2013-06-03 2013-10-09 百度在线网络技术(北京)有限公司 Method for massively calling API interfaces, system for massively calling API interfaces and device for massively calling API interfaces
CN103488765A (en) * 2013-09-28 2014-01-01 雷虹 Access drive and data access method of proxy database
CN111654542A (en) * 2020-06-03 2020-09-11 支付宝(杭州)信息技术有限公司 Proxy server, execution server, reception device, and task execution method
WO2023125038A1 (en) * 2021-12-29 2023-07-06 中兴通讯股份有限公司 Data table preprocessing method and apparatus, and electronic device and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030105745A1 (en) * 2001-12-05 2003-06-05 Davidson Jason A. Text-file based relational database
CN101436184A (en) * 2007-11-15 2009-05-20 金蝶软件(中国)有限公司 Batch data operating method

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030105745A1 (en) * 2001-12-05 2003-06-05 Davidson Jason A. Text-file based relational database
CN101436184A (en) * 2007-11-15 2009-05-20 金蝶软件(中国)有限公司 Batch data operating method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
HTTP://WWW.OSCHINA.NET/CODE/SNIPPET_12_2158: "CsvJdbc示例代码", 《开源中国社区》, 9 December 2010 (2010-12-09) *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103345420A (en) * 2013-06-03 2013-10-09 百度在线网络技术(北京)有限公司 Method for massively calling API interfaces, system for massively calling API interfaces and device for massively calling API interfaces
CN103345420B (en) * 2013-06-03 2017-12-22 百度在线网络技术(北京)有限公司 Batch calls the mthods, systems and devices of api interface
CN103488765A (en) * 2013-09-28 2014-01-01 雷虹 Access drive and data access method of proxy database
CN111654542A (en) * 2020-06-03 2020-09-11 支付宝(杭州)信息技术有限公司 Proxy server, execution server, reception device, and task execution method
CN111654542B (en) * 2020-06-03 2023-03-31 支付宝(杭州)信息技术有限公司 Proxy server, execution server, reception device, and task execution method
WO2023125038A1 (en) * 2021-12-29 2023-07-06 中兴通讯股份有限公司 Data table preprocessing method and apparatus, and electronic device and storage medium

Also Published As

Publication number Publication date
CN102521408B (en) 2015-04-08

Similar Documents

Publication Publication Date Title
US11907247B2 (en) Metadata hub for metadata models of database objects
US8694532B2 (en) Method and system for query transformation for managing information from multiple datasets
CN103823797A (en) FTP (file transfer protocol) based real-time industry database data synchronization system
JP2000148461A (en) Software model and existing source code synchronizing method and device
US20120150797A1 (en) Method and system for safely transporting legacy data to an object semantic form data grid
CN106598612A (en) Operation method and system for data table in database
CN108037916A (en) A kind of graphical service modeling method based on web
CN103778133A (en) Database object changing method and device
KR101899055B1 (en) A database update method based on spreadsheet interface by making queries optimized for updated records
CN113204571B (en) SQL execution method and device related to write-in operation and storage medium
CN104769588B (en) Queue identifying system
EP2852901A1 (en) Methodology supported business intelligence (bi) software and system
CN111367975A (en) Multi-protocol data conversion processing method and device
CN102521408A (en) Method for accessing flat file by using java database connectivity (JDBC) interface
US20040059744A1 (en) Data repository system
CN105975489A (en) Metadata-based online SQL code completion method
CN115543402A (en) Software knowledge graph increment updating method based on code submission
CN113934750A (en) Data blood relationship analysis method based on compiling mode
KR101908556B1 (en) A database update system based on spreadsheet interface by finding out updated records automatically
CN100440803C (en) Gridding information model system and method for modeling processing gridding information
CN110019306A (en) A kind of SQL statement lookup method and system based on XML format file
Fierro Processing USPTO patent data
CN1464435A (en) Process of data exchange between a flush type system and external data base
US20040249792A1 (en) Automated query file conversions upon switching database-access applications
Ioanas et al. LabbookDB: A Wet-Work-Tracking Database Application Framework.

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant