I am currently evaluating the HXTT Text Driver because we have a need to read and process a text file. I am confused on how to map my class to the text file since the text file is not described by any DB. I know from your JDBC examples, you need to issue a "CREATE TABLE" statement to define the layout of the text file you need to manipulate. How is this sort of thing done with Hibernate?
|
First, download HXTT Hibernate Support Package.
Second, please read CREATE TABLE sql. If you're using CSV or TSV table, you needn't even to define CREATE TABLE.
Thirdly, please read connection property table at Connecting to the Database. For instance, you can use jdbc:text:////yourTextFileDirectory?schemaFile=aSchemaFile.sql;fileExtension=TXT . If you stored all "CREATE TABLE" sqls in that aSchemaFile.sql file, HXTT Text (CSV) will load those table declaration sqls .
|
I created "aSchemaFile.sql" and added it to the connection url as follows:
String url = "jdbc:Text:/.?schemaFile=aSchemaFile.sql;fileExtension=idx";
Connection con = DriverManager.getConnection(url, "", "");
Statement stmt = con.createStatement();
stmt.setFetchSize(10);
String sql="select * from \"KeyPayChecks.idx\"";
ResultSet rs = stmt.executeQuery(sql);
However when I do this I get the following stack trace:
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at com.hxtt.sql.text.l.b(Unknown Source)
at com.hxtt.sql.text.l.void(Unknown Source)
at com.hxtt.sql.text.b.a(Unknown Source)
at com.hxtt.sql.text.b.a(Unknown Source)
at com.hxtt.sql.text.e.a(Unknown Source)
at com.hxtt.sql.be.if(Unknown Source)
at com.hxtt.sql.cx.a(Unknown Source)
at com.hxtt.sql.cx.a(Unknown Source)
at com.hxtt.sql.be.a(Unknown Source)
at com.hxtt.sql.be.a(Unknown Source)
at com.hxtt.sql.ab.a(Unknown Source)
at com.hxtt.sql.ab.a(Unknown Source)
at com.hxtt.sql.ab.executeQuery(Unknown Source)
at com.idfbins.keybank.ImageIndexFileServices.getRecords(ImageIndexFileServices.java:94)
at com.idfbins.keybank.Tester.main(Tester.java:15)
java.sql.SQLException: java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at com.hxtt.sql.text.l.b(Unknown Source)
at com.hxtt.sql.text.l.void(Unknown Source)
at com.hxtt.sql.text.b.a(Unknown Source)
at com.hxtt.sql.text.b.a(Unknown Source)
at com.hxtt.sql.text.e.a(Unknown Source)
at com.hxtt.sql.be.if(Unknown Source)
at com.hxtt.sql.cx.a(Unknown Source)
at com.hxtt.sql.cx.a(Unknown Source)
at com.hxtt.sql.be.a(Unknown Source)
at com.hxtt.sql.be.a(Unknown Source)
at com.hxtt.sql.ab.a(Unknown Source)
at com.hxtt.sql.ab.a(Unknown Source)
at com.hxtt.sql.ab.executeQuery(Unknown Source)
at com.idfbins.keybank.ImageIndexFileServices.getRecords(ImageIndexFileServices.java:94)
at com.idfbins.keybank.Tester.main(Tester.java:15)
at com.hxtt.global.SQLState.SQLException(Unknown Source)
at com.hxtt.sql.be.a(Unknown Source)
at com.hxtt.sql.ab.a(Unknown Source)
at com.hxtt.sql.ab.a(Unknown Source)
at com.hxtt.sql.ab.executeQuery(Unknown Source)
at com.idfbins.keybank.ImageIndexFileServices.getRecords(ImageIndexFileServices.java:94)
at com.idfbins.keybank.Tester.main(Tester.java:15)
0
|
That issue was resulted by an invalid default value in your Create Table sql. Supported. Please download the latest package.
If possible, please paste your Create Table sql.
|
You are correct, I was off by one character in the definitions and there was some junk at the end of the sql file I had to delete. Once I found this, it has been working correctly. Thanks for your help.
P.S. It would be nice if a "SQL not valid" exception was thrown when this sort of thing happens. The "array Index out of bounds" is really reporting the effect of the error not the cause.
|
Yeah. So the latest package will stuff/truncate that invalid default value without ArrayIndexOutOfBoundsException.
|