From 468b7748b3df1870bd477d5e46b2f310859534b6 Mon Sep 17 00:00:00 2001 From: Tim McCune Date: Fri, 22 Jul 2005 03:31:10 +0000 Subject: [PATCH] Applied Mitchell Friedman's patch for support of additional JDBC data types. Added CREDITS.txt. git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@18 f203690c-595d-4dc9-a70b-905162fa7fd2 --- CREDITS.txt | 3 +++ .../healthmarketscience/jackcess/Column.java | 13 +++++++----- .../jackcess/DataType.java | 8 ++++++++ .../jackcess/Database.java | 20 +++++++++++++------ xdocs/faq.fml | 14 +++++++++++++ 5 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 CREDITS.txt diff --git a/CREDITS.txt b/CREDITS.txt new file mode 100644 index 0000000..f78ece8 --- /dev/null +++ b/CREDITS.txt @@ -0,0 +1,3 @@ +Tim McCune - Original author and project founder +Rob DiMarco - Added ability to import delimited text into new tables +Mitchell J. Friedman - Added support for additional JDBC data types diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index cb0b64d..54602cc 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -404,18 +404,21 @@ public class Column implements Comparable { } ByteBuffer buffer = ByteBuffer.allocate(size); buffer.order(order); + if (obj instanceof Boolean) { + obj = ((Boolean) obj) ? 1 : 0; + } if (_type == DataType.BOOLEAN) { //Do nothing } else if (_type == DataType.BYTE) { - buffer.put(((Byte) obj).byteValue()); + buffer.put(((Number) obj).byteValue()); } else if (_type == DataType.INT) { - buffer.putShort(((Short) obj).shortValue()); + buffer.putShort(((Number) obj).shortValue()); } else if (_type == DataType.LONG) { - buffer.putInt(((Integer) obj).intValue()); + buffer.putInt(((Number) obj).intValue()); } else if (_type == DataType.DOUBLE) { - buffer.putDouble(((Double) obj).doubleValue()); + buffer.putDouble(((Number) obj).doubleValue()); } else if (_type == DataType.FLOAT) { - buffer.putFloat(((Float) obj).floatValue()); + buffer.putFloat(((Number) obj).floatValue()); } else if (_type == DataType.SHORT_DATE_TIME) { Calendar cal = Calendar.getInstance(); cal.setTime((Date) obj); diff --git a/src/java/com/healthmarketscience/jackcess/DataType.java b/src/java/com/healthmarketscience/jackcess/DataType.java index ce23c25..e7747c6 100644 --- a/src/java/com/healthmarketscience/jackcess/DataType.java +++ b/src/java/com/healthmarketscience/jackcess/DataType.java @@ -62,6 +62,14 @@ public enum DataType { SQL_TYPES.put(type._sqlType, type); } } + SQL_TYPES.put(Types.BIT, BYTE); + SQL_TYPES.put(Types.BLOB, OLE); + SQL_TYPES.put(Types.BIGINT, LONG); + SQL_TYPES.put(Types.CHAR, TEXT); + SQL_TYPES.put(Types.DATE, SHORT_DATE_TIME); + SQL_TYPES.put(Types.REAL, DOUBLE); + SQL_TYPES.put(Types.TIME, SHORT_DATE_TIME); + SQL_TYPES.put(Types.VARBINARY, BINARY); } private static Map DATA_TYPES = new HashMap(); diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 4aaf508..5447dd2 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -546,16 +546,24 @@ public class Database { int textCount = 0; int totalSize = 0; for (int i = 1; i <= md.getColumnCount(); i++) { - switch (md.getColumnType(i)) { - case Types.INTEGER: - case Types.FLOAT: + DataType accessColumnType = DataType.fromSQLType(md.getColumnType(i)); + switch (accessColumnType) { + case BYTE: + case INT: + case LONG: + case MONEY: + case FLOAT: + case NUMERIC: totalSize += 4; break; - case Types.DOUBLE: - case Types.DATE: + case DOUBLE: + case SHORT_DATE_TIME: totalSize += 8; break; - case Types.VARCHAR: + case BINARY: + case TEXT: + case OLE: + case MEMO: textCount++; break; } diff --git a/xdocs/faq.fml b/xdocs/faq.fml index ce2e1b3..93c05f4 100644 --- a/xdocs/faq.fml +++ b/xdocs/faq.fml @@ -110,6 +110,20 @@ + + Why do I get a NoClassDefFoundError? + +

+ Probably because you're missing a jar that Jackcess depends on from your + classpath. Take a loook at the dependencies list. The first 3 are required for both building and running + and can be found either at the + Jakarta Commons or the Ibiblio + Maven Repository. The other 3 are only required for building, in which + case, Maven will find them for you. +

+
+
+ Who is Health Market Science? -- 2.39.5