我的Java代码是:
conn = DriverManager.getConnection(url, "user", "password"); // line 1
stm = conn.createStatement(); // line 2
stm.execute("CREATE TEXT TABLE someTableName("NLID" VARCHAR(20),
"Scheduled.Primary.Scripting.Code" VARCHAR(20), "Scheduled.Site" VARCHAR(20),
"Scheduled.Location.Long.Name" VARCHAR(20),
"primary_key_1644" int PRIMARY KEY)"); // line 3
stm.execute("SET TABLE someTableName SOURCE
"/some.csv;ignore_first=true;all_quoted=true;shutdown=true""); // line 4
链接到 hsqldb 的 CSV 是:
NLID,Scheduled.Primary.Scripting.Code,Scheduled.Site,Scheduled.Location.Long.Name,primary_key_1644
100,INMRSB,Shopping,Shopping General-Banner-728x90-INMRSB-I,1
100002,MSVT08,MSN Video,msnbc.com-TODAYshow.com Special Sponsorships 8-Streaming Media-300x60-MSVT08-S,2
100004,MSV10T,MSN Video,msnbc.com-TODAYshow.com Special Sponsorships 10-Streaming Media-300x60-MSV10T-S,3
我在第 4 行得到以下异常:
java.sql.SQLException: bad TEXT table source file - line number: 1196 java.lang.NumberFormatException: For input string: "Body Connection-Banner-728x90-HEAMBA-S" in statement [SET TABLE someTableName SOURCE "/some.csv;ignore_first=true;all_quoted=true;shutdown=true"]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
at java.lang.NumberFormatException: For input string: "Body Connection-Banner-728x90-HEAMBA-S"
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.TextTable.connect(Unknown Source)
at org.hsqldb.TextTable.openCache(Unknown Source)
at org.hsqldb.TextTable.setDataSource(Unknown Source)
at org.hsqldb.StatementCommand.getResult(Unknown Source)
at org.hsqldb.StatementCommand.execute(Unknown Source)
at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 6 more
Caused by: java.lang.NumberFormatException: For input string: "Body Connection-Banner-728x90-HEAMBA-S"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.hsqldb.rowio.RowInputText.readInteger(Unknown Source)
at org.hsqldb.rowio.RowInputBase.readData(Unknown Source)
at org.hsqldb.rowio.RowInputText.readData(Unknown Source)
at org.hsqldb.rowio.RowInputBase.readData(Unknown Source)
at org.hsqldb.rowio.RowInputText.readData(Unknown Source)
at org.hsqldb.RowAVLDiskData.getRowData(Unknown Source)
at org.hsqldb.persist.RowStoreAVLDiskData.get(Unknown Source)
... 14 more
任何帮助都将是可观的。
编辑: Hsqldb 在读取定义为 VARCHAR 的列时抛出 NumberFormatException !!!
MODIFIED:发生异常是因为其中一个列值中包含逗号,例如"Mind, Body Connection-Banner-728x90-HEAMBA-S"
。由于 hsqldb 将 csv 作为表读取,因此附加逗号被 hsql 解释为附加列。谁能指导我如何规避这个?