Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6601029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:42:02+00:00 2026-05-25T18:42:02+00:00

I have a pregenerated CSV file on which I need to run SQL queries.

  • 0

I have a pregenerated CSV file on which I need to run SQL queries. I’ve been looking at different open source solutions (e.g. CsvJdbc, xlSQL etc) but haven’t really found anything satisfactory.

CsvJdbc couldn’t recognize ORDER BY, GROUP BY etc
xlSQL only runs on XLS files, not CSV (or I haven’t been able to get it to run with CSV. Anybody know how?). Plus it’s not in development or supported anymore.

I read somewhere that HSQLDB supports querying on CSV files, but I haven’t been able to work it correctly. Here’s what I’ve done till now:

If I create a CSV File using HSQLDB, then it’s able to execute queries successfully. Here’s the code for that:

String driver = "org.hsqldb.jdbcDriver";
Driver d = (Driver) Class.forName(driver).newInstance();
String protocol = "jdbc:hsqldb:file";
final String url = "jdbc:hsqldb:file:/C:/Users/varun.achar/Documents";

final StringBuilder createTable = new StringBuilder();
createTable.append("CREATE TEXT TABLE currency (");
createTable.append("id INT PRIMARY KEY, name VARCHAR)");
final StringBuilder linkTable = new StringBuilder();
linkTable.append("SET TABLE currency SOURCE ");
linkTable.append("\"/currencies.csv");
linkTable.append(";ignore_first=true;all_quoted=true\"");
Connection conn = DriverManager.getConnection(url, "sa", "");
Statement stm = conn.createStatement();
stm.execute(createTable.toString());
stm.execute(linkTable.toString());
ResultSet resultSet = stm.executeQuery("SELECT * FROM CURRENCY");
if (resultSet != null) {
    while (resultSet.next()) {
        System.out.println("CURRENCY = " + resultSet.getString(2));
    }
}
conn.close();

But the same thing doesn’t work when I delete the file and run it again! I get the error

Table already exists: CURRENCY in statement [CREATE TEXT TABLE currency]

Also, If I have a pre-existing csv file ( the formatting is correct since I was able to run a simple select statement using CsvJDBC) then I get the error

Table not found: RMS in statement [SET TABLE rms]

Code for this

final StringBuilder linkTable = new StringBuilder();
linkTable.append("SET TABLE rms SOURCE ");
linkTable.append("\"C:/myreports/temp/user/1316083232009/rms.csv");
linkTable.append(";ignore_first=true;all_quoted=true\"");
Driver d = (Driver) Class.forName(driver).newInstance();
System.out.println("Driver was successfully loaded.");
String protocol = "jdbc:hsqldb:file";
String database = "C:\\myreports\\temp\\user\\1316083232009\\rms.csv";
String url = protocol + ":" + database;
con = DriverManager.getConnection(url);
stm = con.createStatement();
stm.execute(linkTable.toString());
resultSet = stm.executeQuery(testSQLStatement());
if (resultSet != null) {
    while (resultSet.next()) {
        System.out.println("FULL NAME = "+ resultSet.getString("usr_FULL_NAME"));
    }
}

Can somebody throw some light on this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:42:02+00:00Added an answer on May 25, 2026 at 6:42 pm

    A single HSQLDB database can have many tables, including several TEXT tables. It seems you think there must be one database per each text table, which is not the case.

    The database path is not a directory. It is not a CSV file either. In your first example you should specify a database name such as this:

    final String url = "jdbc:hsqldb:file:/C:/Users/varun.achar/Documents/mydb";
    

    The same in your second example.

    The database consists of a few files beginning with the names you sepcified. In this example, you will have mydb.properties, mydb.script, etc.

    The CREATE TEXT TABLE ... statement creates the metadata for the table. This table metadata is persisted in the database.

    The first example will then work. If you delete the CSV file, then open the database, the ‘CREATE TEXT TABLE’ statement is still stored in the database, therefore it complains when you attempt to create the same table again.

    If you have a preexisting CVS file, you still need to start with CREATE TEXT TABLE ..., then link it with the CVS using the SET TABLE statement, the same way as the first example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winforms app which has an app.config. If the config file is
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a LINQ-to-SQL Generator class in a project I'm working on, and to
I have a trigger that gets inserts and updates to a view. I need
Greetings, Well I am bewildered. I have been tasked with updating a PHP script
Say I have a web project which uses a WCF service for behind-the-scenes processing,
I have some conditionals in my InitializeComponent which affect the layout based on some
I am using linq to sql and I have 2 tables(sedan, suv: they are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.