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 7893637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:11:00+00:00 2026-06-03T07:11:00+00:00

Description: if there is a violation of foreign key constraint when importing a .txt

  • 0

Description:
if there is a violation of foreign key constraint when importing a .txt file, it seems I cannot get the line number of the line which violate the FK constraint in the message of the JdbcSQLException.
I’ve uploaded the exceptions and codes onto the “mysticpaste” website, Please take a look, the information I want is like “error on line [line number] of file [file address]”, the derby provides this kind of information but the H2 doesn’t, do you know how to get this information?

Attachment:
click the following link to download a java project and import to you IDE, so that you can run the helloworld and get the exception I described.

https://rapidshare.com/files/3028771943/Test.rar

if you can run the above project, ignore the following links.

Links for Source codes and related exceptions:

h2’s helloWorld:
http://www.mysticpaste.com/view/13500

h2’s related exception:
http://www.mysticpaste.com/view/13502

derby’s helloWorld:
http://www.mysticpaste.com/view/13499

derby’s related exception:
http://www.mysticpaste.com/view/13503

Source codes:

public class HelloWorld_h2 {

    /**
     * this method is to display an error message when there is foreign key constraint violation.
     *
     * @param args ignored
     */
    public static void main(String... args) throws Exception {
        // delete the database named 'test' in the user home directory
        DeleteDbFiles.execute("~", "test", true);

        Class.forName("org.h2.Driver");
        Connection conn = DriverManager.getConnection("jdbc:h2:~/test");
        Statement stat = conn.createStatement();

        // this line would initialize the database
        // from the SQL script file 'init.sql'
        // stat.execute("runscript from 'init.sql'");

        stat.execute("create table test1(" +
                "id int primary key, " +
            "name varchar(255))");

        stat.execute("create table test2(" +
            "id int primary key, " +
            "name varchar(255)," +
            "constraint fk_test2 foreign key (name) references test1(name))");

        stat.execute("insert into test1 (select * from CSVREAD("+"'classpath:test1.txt'"+",'id,name','charset=UTF-8 fieldSeparator=,'))");
        stat.execute("insert into test2 (select * from CSVREAD("+"'classpath:test2.txt'"+",'id,name','charset=UTF-8 fieldSeparator=,'))");

        stat.close();
        conn.close();
    }
}

public class HelloWorld_derby {

    /**
     * this method is to display an error message when there is foreign key constraint violation.
     *
     * @param args ignored
     */
    public static void main(String... args) throws Exception {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        Connection conn = DriverManager.getConnection("jdbc:derby:memory:test;create=true;","","");
        Statement stat = conn.createStatement();

        // this line would initialize the database
        // from the SQL script file 'init.sql'
        // stat.execute("runscript from 'init.sql'");

        stat.execute("create table test1(" +
            "id int primary key, " +
            "name varchar(255) unique)");

        stat.execute("create table test2(" +
            "id int primary key, " +
            "name varchar(255)," +
            "constraint fk_test2 foreign key (name) references test1(name))");

        String classpath = new HelloWorld_derby().getClass().getResource("/").getFile();
        String test1_url = classpath + "test1.txt";
        String test2_url = classpath + "test2.txt";

        CallableStatement c1 = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE (null,'TEST1','"+test1_url+"',',','\"','UTF-8',1 )");
        c1.execute();
        CallableStatement c2 = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE (null,'TEST2','"+test2_url+"',',','\"','UTF-8',1 )");
        c2.execute();

        stat.close();
        conn.close();
    }
}
  • 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-06-03T07:11:01+00:00Added an answer on June 3, 2026 at 7:11 am

    The easiest solution is to upgrade from H2 version 1.3.164 (what you are using) to H2 version 1.3.165 or newer. Version 1.3.165 includes the values of a referential constraint violation in the error message, as described in the change log: “In error messages about referential constraint violation, the values are now included.”

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

Sidebar

Related Questions

Is there a simple description of how the dictionary file in Proguard should be
Problem description There are different categories which contain an arbitrary amount of elements .
Short description of my setup: There is an SQLObject base class which has an
Is there any implementation (or straightforward description) of a training algorithm for feed-forward neural
Is there any body can confirm the description here is true? My experience is
On Github there is an description how to build the framework from scratch. How
(Is there a way to | How do I) include a custom description for
There is some type Record : type Day = Integer type Description = String
In Suzanne Cook's blog there is such a description: LoadFrom Context: In general, if
FYI, There is some overlap in the initial description of this question with a

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.