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

  • SEARCH
  • Home
  • 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 7510715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:18:27+00:00 2026-05-29T23:18:27+00:00

I want to use HSQLDB as an embedded database but am having trouble getting

  • 0

I want to use HSQLDB as an embedded database but am having trouble getting it to auto-increment.

As far as I understand, [CALL] IDENTITY() can be used to get the last primary key value. However, experiments through both iBatis and HSQLDB’s DatabaseManagerSwing continually return a 0 value.

How can I get auto-incrementation to work with HSQLDB?

Edit:

I didn’t mention that I’m using DDLUtils to autogenerate tables. The following does not suit HSQLDB:

<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database.dtd">

<database name="testdb">

    <table name="users">
        <!-- using autoincrement attribute below causes
        "primary key already exists" exception -->
        <column name="id" type="INTEGER" primaryKey="true" />
        <column name="username" type="VARCHAR" size="30" />
        <column name="password" type="VARCHAR" size="100" />
    </table>

</database>

Also, here is the iBatis SQL map used for the domain class:

<insert id="insertUser" parameterClass="user">
    <selectKey keyProperty="id" resultClass="int">
        CALL IDENTITY()
    </selectKey>
INSERT INTO USERS
( USERNAME, PASSWORD ) 
VALUES
( #username#, #password#)       
</insert>
  • 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-29T23:18:29+00:00Added an answer on May 29, 2026 at 11:18 pm

    Here’s an example that prints out

    0
    1
    2
    

    on my machine:

    import java.io.File;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Date;
    
    public class Test {
    
      public static void main(String[] args) throws Exception {
    
        File dbDir = new File("/tmp/identity_test"); 
        String connectionTemplate = "jdbc:hsqldb:file:%s/test";
        String connStr = String.format(connectionTemplate, dbDir);
        Connection connection = DriverManager.getConnection(connStr, "", "");
        Statement s = connection.createStatement();
        s.execute("CREATE TABLE test (id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, s VARCHAR(10))");
        PreparedStatement psInsert = connection.prepareStatement("INSERT INTO test (s) VALUES (?)");
        for (int i = 0; i < 3; i++) {
          psInsert.setString(1, "hello");
          psInsert.executeUpdate();
          PreparedStatement psIdentity = connection.prepareStatement("CALL IDENTITY()");
          ResultSet result = psIdentity.executeQuery();
          result.next();
          int identity = result.getInt(1);
          result.close();
          System.out.println(identity);
        }
        connection.close();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use an in-memory database to test my application, but it needs
I want to use an in-memory database to test my application, but it needs
I want to use the Web Browser control within an mono application, but when
I want use a typedef struct that isn't already defined, but it is later.
I want to use HyperSQL as an in-memory database for integration tests of a
I've just downloaded hsqldb version 2.2.28 and I want to convert a mysql database
I want use Kendo ui window, but I can't see what the problem is.
I want use i18n internationalization. CRUD its works fine, but with custom routes something
I use hsqldb to run my unit tests that need a database access. For
I want use glassfish as the solr search server, but I don't know how

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.