Home arrow Java arrow Page 2 - Using CSV Files as Databases and Interacting with Them Using Java

Using CSV Files as Databases and Interacting with Them Using Java

In this article, we’ll show the reader how to use a simple CSV (comma-separated values) file as a simplistic database setup.  We will leverage the JDBC-ODBC to interact with a CSV file, reading and writing to it with SQL.  Such a technique can be particularly useful for someone trying to write simple database code, but not able to because a local database instance is not pragmatic. 

Author Info:
By: Kulvir S. Bhogal & Kwang Sik Kang
Rating: 4 stars4 stars4 stars4 stars4 stars / 86
January 28, 2004
  1. · Using CSV Files as Databases and Interacting with Them Using Java
  2. · Creating an ODBC Data Source
  3. · Let's Interact

print this article

Using CSV Files as Databases and Interacting with Them Using Java - Creating an ODBC Data Source
(Page 2 of 3 )

As stated earlier, we will interact with the CSV file as an ODBC source. To do this, we will use the ODBC Data Source Administrator to define the file as an ODBC data source. From the control panel’s Administrative Tools, double click the “Data Sources (ODBC)” to open the ODBC Data Source Administrator (See Figure 2).

Installing ODBC
Figure 2: The Data Sources Administrative Tool

From the ODBC Data Source Administrator’s “User DSN” tab, click “Add…” to define a new user data source (See Figure 3).

Installing ODBC
Figure 3: The ODBC Data Source Administrator

Select the “Microsoft Text Driver” and click “Finish” (see Figure 4). 

Installing ODBC
Figure 4: Choosing the Microsoft Text Driver

From the “ODBC Text Setup” window, click on the “Options>>” button to reveal additional properties. Name the data source “StateBirdDS” as shown in Figure 5. Deselect the “Use Current Directory” checkbox and click on the “Select Directory” button to reference the provided “statebirds.txt” file. Next, click on the “Define Format…” button.

Installing ODBC
Figure 5: Defining Your Data Source

From the “Define Text Format” window’s “Tables” pane, select “statebirds.txt”.  Select the “Column Name Header” checkbox and input 1 for the “Rows to Scan” option.  Next, click the “Guess” button and you will see that the Columns pane is populated as shown in Figure 6. There is an option to override the Data Types that were extrapolated to accommodate your needs.  However, for this exercise, the data type of Char with a width of 255 is fine.

Installing ODBC
Figure 6: Defining the Text Format

A “Failed to save table attributes of (null) into (null)” error may be thrown (See Figure 7).  This is a known with the Microsoft Text Driver.  Read about how to remedy the problem in the Microsoft Knowledge Base

Installing ODBC
Figure 7: An Error That Might Be Thrown

When all is said and done, the created data source (StateBirdDS) should appear in your list of User Data Sources. (See Figure 8)

Installing ODBC
Figure 8: Seeing the New Data Source You Created

blog comments powered by Disqus

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials