Java-based access to vfdatabases

Source: Internet
Author: User

During this time, the project has been busy, and CSDN has been obsolete for some time. Now the project is about to be accepted. Take some time to sort out the knowledge points used in the project for future study and reference. Because the data of another system needs to be obtained in the actual project, you may have thought that the accessed system data is the vfdatabase I want to talk about below.
VF programming language has never been used before. Most of the development tools use Visual Foxpro 7.0. The version may not be the latest. Configure the development environment, familiarize yourself with the syntax, and write the demo program for half a day. Unlike MySql and Oracle databases, vfdatabases can be used on Visual Foxpro 7.0 development tools for new projects and databases, similar to VB. . Dbf is the suffix of the table file. The CDX file is the index associated with the table.
The specific function of the project is to display daily data in the form of reports. This function has been implemented in the VF system. The data displayed in the table is obtained from the temporary table, and the data in the temporary table needs to be computed by accessing the data in the six tables, that is, the data displayed in the table has no historical records, and each query is recalculated based on the date. Here, of course, I can't get the data in a temporary table. Instead, I want to access the data in the six tables mentioned above. After the data is generated every day, I need to compute and store it in another table. A record corresponds to the data of the day. The report shows that the data of the day is actually the data record of the day in the data table.
The following is the Java programming implementation for vfdatabase access:
[Html]
<Span style = "font-size: 14px;"> // store the table data of the VF database to be accessed. During the test, the table data is stored locally.
Private static String filePath = "D:/ddrbdatas ";
Public static Connection getConn (){
Connection conn = null;
Try {
Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
String strurl = "jdbc: odbc: Driver = {Microsoft Visual FoxPro Driver}; UID =; SourceType = DBF; SourceDB =" + filePath + "; Exclusive = No ;";
Conn = DriverManager. getConnection (strurl );
} Catch (ClassNotFoundException e ){
E. printStackTrace ();
} Catch (SQLException e ){
E. printStackTrace ();
}
Return conn;
}
 
Public static PreparedStatement prepare (Connection conn, String SQL ){
PreparedStatement pstmt = null;
Try {
If (conn! = Null ){
Pstmt = conn. prepareStatement (SQL );
}
} Catch (SQLException e ){
E. printStackTrace ();
}
Return pstmt;
}

Public static ResultSet getResultSet (PreparedStatement stmt ){
ResultSet rs = null;
Try {
If (stmt! = Null ){
Rs = stmt.exe cuteQuery ();
}
} Catch (SQLException e ){
E. printStackTrace ();
}
Return rs;
} </Span>
The Data Access trilogy is here. With rs, We can traverse every record in the data table cyclically and retrieve the desired field value!

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.