本文整理汇总了Java中com.healthmarketscience.jackcess.Table.addRow方法的典型用法代码示例。如果您正苦于以下问题:Java Table.addRow方法的具体用法?Java Table.addRow怎么用?Java Table.addRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.healthmarketscience.jackcess.Table
的用法示例。
在下文中一共展示了Table.addRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: x_testCreateIsoFile
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void x_testCreateIsoFile() throws Exception
{
Database db = create(Database.FileFormat.V2000, true);
Table t = new TableBuilder("test")
.addColumn(new ColumnBuilder("row", DataType.TEXT))
.addColumn(new ColumnBuilder("data", DataType.TEXT))
.toTable(db);
for(int i = 0; i < 256; ++i) {
String str = "AA" + ((char)i) + "AA";
t.addRow("row" + i, str);
}
db.close();
}
示例2: addCombos
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
private int addCombos(Table t, int rowNum, String s, char[] cs, int len)
throws Exception
{
if(s.length() >= len) {
return rowNum;
}
for(int i = 0; i < cs.length; ++i) {
String name = "row" + (rowNum++);
String ss = s + cs[i];
t.addRow(name, ss);
rowNum = addCombos(t, rowNum, ss, cs, len);
}
return rowNum;
}
示例3: testLongValueAsMiddleColumn
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void testLongValueAsMiddleColumn() throws Exception
{
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
Table newTable = new TableBuilder("NewTable")
.addColumn(new ColumnBuilder("a").setSQLType(Types.INTEGER))
.addColumn(new ColumnBuilder("b").setSQLType(Types.LONGVARCHAR))
.addColumn(new ColumnBuilder("c").setSQLType(Types.VARCHAR))
.toTable(db);
String lval = createString(2000); // "--2000 chars long text--";
String tval = createString(40); // "--40chars long text--";
newTable.addRow(new Integer(1), lval, tval);
newTable = db.getTable("NewTable");
Map<String, Object> readRow = newTable.getNextRow();
assertEquals(new Integer(1), readRow.get("a"));
assertEquals(lval, readRow.get("b"));
assertEquals(tval, readRow.get("c"));
db.close();
}
}
示例4: doTestWriteAndRead
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
private static void doTestWriteAndRead(Database db) throws Exception {
createTestTable(db);
Object[] row = createTestRow();
row[3] = null;
Table table = db.getTable("Test");
int count = 1000;
((DatabaseImpl)db).getPageChannel().startWrite();
try {
for (int i = 0; i < count; i++) {
table.addRow(row);
}
} finally {
((DatabaseImpl)db).getPageChannel().finishWrite();
}
for (int i = 0; i < count; i++) {
Map<String, Object> readRow = table.getNextRow();
assertEquals(row[0], readRow.get("A"));
assertEquals(row[1], readRow.get("B"));
assertEquals(row[2], readRow.get("C"));
assertEquals(row[3], readRow.get("D"));
assertEquals(row[4], readRow.get("E"));
assertEquals(row[5], readRow.get("F"));
assertEquals(row[6], readRow.get("G"));
assertEquals(row[7], readRow.get("H"));
}
}
示例5: testNoEnforceForeignKeys
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void testNoEnforceForeignKeys() throws Exception {
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {
Database db = openCopy(testDB);
db.setEnforceForeignKeys(false);
Table t1 = db.getTable("Table1");
Table t2 = db.getTable("Table2");
Table t3 = db.getTable("Table3");
t1.addRow(20, 0, 20, "some data", 20);
Cursor c = CursorBuilder.createCursor(t2);
c.moveToNextRow();
c.updateCurrentRow(30, "foo30");
c = CursorBuilder.createCursor(t3);
c.moveToNextRow();
c.deleteCurrentRow();
db.close();
}
}
示例6: x_testCreateAltIsoFile
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void x_testCreateAltIsoFile() throws Exception
{
Database db = openCopy(Database.FileFormat.V2000, new File("/tmp/test_ind.mdb"), true);
Table t = db.getTable("Table1");
for(int i = 0; i < 256; ++i) {
String str = "AA" + ((char)i) + "AA";
t.addRow("row" + i, str,
(byte)42 + i, (short)53 + i, 13 * i,
(6.7d / i), null, null, true);
}
db.close();
}
示例7: writeChars
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
private void writeChars(int hibyte, Table t) throws Exception
{
char other = (char)(hibyte | 0x41);
for(int i = 0; i < 0xFF; ++i) {
char c = (char)(hibyte | i);
String str = "" + other + c + other;
t.addRow(str);
}
}
示例8: testAutoNumberGuid
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void testAutoNumberGuid() throws Exception
{
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
Table table = new TableBuilder("test")
.addColumn(new ColumnBuilder("a", DataType.GUID)
.setAutoNumber(true))
.addColumn(new ColumnBuilder("b", DataType.TEXT))
.toTable(db);
Object[] row = {null, "row1"};
assertSame(row, table.addRow(row));
assertTrue(ColumnImpl.isGUIDValue(row[0]));
row = table.addRow(13, "row2");
assertTrue(ColumnImpl.isGUIDValue(row[0]));
row = table.addRow("flubber", "row3");
assertTrue(ColumnImpl.isGUIDValue(row[0]));
Object[] smallRow = {Column.AUTO_NUMBER};
row = table.addRow(smallRow);
assertNotSame(row, smallRow);
assertTrue(ColumnImpl.isGUIDValue(row[0]));
db.close();
}
}
示例9: export
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public ActionForward export(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws Exception {
InputStream inputStream =
ExportParkingDataToAccessDatabaseDA.class.getClassLoader().getResourceAsStream("templates/Cartoes_XML.mdb");
if (inputStream != null) {
File temp = FileUtils.copyToTemporaryFile(inputStream);
Database db = Database.open(temp, Boolean.FALSE, Boolean.TRUE);
Table xml = db.getTable("XML");
List<ParkingParty> parkingParties = getValidParkingParties();
for (ParkingParty parkingParty : parkingParties) {
Object[] newRow = new Object[28];
fillInRow(parkingParty, newRow);
xml.addRow(newRow);
}
response.setContentType("application/vnd.ms-access");
response.setHeader("Content-disposition", "attachment; filename=Cartões_XML.mdb");
final ServletOutputStream writer = response.getOutputStream();
writer.write(Files.toByteArray(temp));
writer.flush();
writer.close();
response.flushBuffer();
inputStream.close();
}
return null;
}
示例10: renderReport
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void renderReport(File parkingDataFile) throws Exception {
Database db = Database.open(parkingDataFile, Boolean.FALSE, Boolean.TRUE);
Table xml = db.getTable("XML");
List<ParkingParty> parkingParties = getValidParkingParties();
final Date now = new DateTime().toDate();
final Map<String, Integer> parkingGroupCodes = getParkingGroupCodes();
for (ParkingParty parkingParty : parkingParties) {
if (parkingParty.getCardNumber() != 0) {
Object[] newRow = new Object[28];
fillInRow(parkingParty, newRow, parkingGroupCodes, now);
xml.addRow(newRow);
}
}
}
示例11: testExportToFile
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void testExportToFile() throws Exception
{
DateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
df.setTimeZone(TEST_TZ);
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
db.setTimeZone(TEST_TZ);
Table t = new TableBuilder("test")
.addColumn(new ColumnBuilder("col1", DataType.TEXT))
.addColumn(new ColumnBuilder("col2", DataType.LONG))
.addColumn(new ColumnBuilder("col3", DataType.DOUBLE))
.addColumn(new ColumnBuilder("col4", DataType.OLE))
.addColumn(new ColumnBuilder("col5", DataType.BOOLEAN))
.addColumn(new ColumnBuilder("col6", DataType.SHORT_DATE_TIME))
.toTable(db);
Date testDate = df.parse("19801231 00:00:00");
t.addRow("some text||some more", 13, 13.25, createString(30).getBytes(),
true, testDate);
t.addRow("crazy'data\"here", -345, -0.000345, createString(7).getBytes(),
true, null);
t.addRow("C:\\temp\\some_file.txt", 25, 0.0, null, false, null);
StringWriter out = new StringWriter();
new ExportUtil.Builder(db, "test")
.exportWriter(new BufferedWriter(out));
String expected =
"some text||some more,13,13.25,\"61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78\n79 7A 61 62 63 64\",true," + testDate + NL +
"\"crazy'data\"\"here\",-345,-3.45E-4,61 62 63 64 65 66 67,true," + NL +
"C:\\temp\\some_file.txt,25,0.0,,false," + NL;
assertEquals(expected, out.toString());
out = new StringWriter();
new ExportUtil.Builder(db, "test")
.setHeader(true)
.setDelimiter("||")
.setQuote('\'')
.exportWriter(new BufferedWriter(out));
expected =
"col1||col2||col3||col4||col5||col6" + NL +
"'some text||some more'||13||13.25||'61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78\n79 7A 61 62 63 64'||true||" + testDate + NL +
"'crazy''data\"here'||-345||-3.45E-4||61 62 63 64 65 66 67||true||" + NL +
"C:\\temp\\some_file.txt||25||0.0||||false||" + NL;
assertEquals(expected, out.toString());
ExportFilter oddFilter = new SimpleExportFilter() {
private int _num;
@Override
public Object[] filterRow(Object[] row) {
if((_num++ % 2) == 1) {
return null;
}
return row;
}
};
out = new StringWriter();
new ExportUtil.Builder(db, "test")
.setFilter(oddFilter)
.exportWriter(new BufferedWriter(out));
expected =
"some text||some more,13,13.25,\"61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78\n79 7A 61 62 63 64\",true," + testDate + NL +
"C:\\temp\\some_file.txt,25,0.0,,false," + NL;
assertEquals(expected, out.toString());
}
}
示例12: testBigInt
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void testBigInt() throws Exception {
for (final Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
JetFormat format = DatabaseImpl.getFileFormatDetails(fileFormat)
.getFormat();
if(!format.isSupportedDataType(DataType.BIG_INT)) {
continue;
}
Database db = create(fileFormat);
Table t = new TableBuilder("Test")
.addColumn(new ColumnBuilder("id", DataType.LONG)
.setAutoNumber(true))
.addColumn(new ColumnBuilder("data1", DataType.TEXT))
.addColumn(new ColumnBuilder("num1", DataType.BIG_INT))
.addIndex(new IndexBuilder("idx").addColumns("num1"))
.toTable(db);
long[] vals = new long[] {
0L, -10L, 3844L, -45309590834L, 50392084913L, 65000L, -6489273L};
List<Map<String, Object>> expectedTable =
new ArrayList<Map<String, Object>>();
int idx = 1;
for(long lng : vals) {
t.addRow(Column.AUTO_NUMBER, "" + lng, lng);
expectedTable.add(createExpectedRow(
"id", idx++,
"data1", "" + lng,
"num1", lng));
}
Collections.sort(expectedTable, new Comparator<Map<String, Object>>() {
public int compare(
Map<String, Object> r1,
Map<String, Object> r2) {
Long l1 = (Long)r1.get("num1");
Long l2 = (Long)r2.get("num1");
return l1.compareTo(l2);
}
});
Cursor c = new CursorBuilder(t).setIndexByName("idx").toIndexCursor();
assertCursor(expectedTable, c);
db.close();
}
}
示例13: writeData
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
private static void writeData(Table t1, Table t2, int start, int end)
throws Exception
{
Database db = t1.getDatabase();
((DatabaseImpl)db).getPageChannel().startWrite();
try {
for(int i = start; i < end; ++i) {
t1.addRow(null, "rowdata-" + i + TestUtil.createString(100));
t2.addRow(null, "rowdata-" + i + TestUtil.createString(100));
}
} finally {
((DatabaseImpl)db).getPageChannel().finishWrite();
}
Cursor c1 = t1.newCursor().setIndex(t1.getPrimaryKeyIndex())
.toCursor();
Cursor c2 = t2.newCursor().setIndex(t2.getPrimaryKeyIndex())
.toCursor();
Iterator<? extends Row> i1 = c1.iterator();
Iterator<? extends Row> i2 = c2.newIterable().reverse().iterator();
int t1rows = 0;
int t2rows = 0;
((DatabaseImpl)db).getPageChannel().startWrite();
try {
while(i1.hasNext() || i2.hasNext()) {
if(i1.hasNext()) {
checkRow(i1.next());
i1.remove();
++t1rows;
}
if(i2.hasNext()) {
checkRow(i2.next());
i2.remove();
++t2rows;
}
}
} finally {
((DatabaseImpl)db).getPageChannel().finishWrite();
}
assertEquals(100, t1rows);
assertEquals(100, t2rows);
}
示例14: testWriteLongValue
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
public void testWriteLongValue() throws Exception {
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
Table table =
new TableBuilder("test")
.addColumn(new ColumnBuilder("A", DataType.TEXT))
.addColumn(new ColumnBuilder("B", DataType.MEMO))
.addColumn(new ColumnBuilder("C", DataType.OLE))
.toTable(db);
String testStr = "This is a test";
String longMemo = createString(2030);
byte[] oleValue = toByteArray(new File("src/test/data/test2BinData.dat"));
table.addRow(testStr, testStr, null);
table.addRow(testStr, longMemo, oleValue);
table.addRow("", "", new byte[0]);
table.addRow(null, null, null);
table.reset();
Row row = table.getNextRow();
assertEquals(testStr, row.get("A"));
assertEquals(testStr, row.get("B"));
assertNull(row.get("C"));
row = table.getNextRow();
assertEquals(testStr, row.get("A"));
assertEquals(longMemo, row.get("B"));
assertTrue(Arrays.equals(oleValue, row.getBytes("C")));
row = table.getNextRow();
assertEquals("", row.get("A"));
assertEquals("", row.get("B"));
assertTrue(Arrays.equals(new byte[0], row.getBytes("C")));
row = table.getNextRow();
assertNull(row.get("A"));
assertNull(row.get("B"));
assertNull(row.getBytes("C"));
db.close();
}
}
示例15: doTestAutoNumber
import com.healthmarketscience.jackcess.Table; //导入方法依赖的package包/类
private static void doTestAutoNumber(Table table) throws Exception
{
Object[] row = {null, "row1"};
assertSame(row, table.addRow(row));
assertEquals(1, ((Integer)row[0]).intValue());
row = table.addRow(13, "row2");
assertEquals(2, ((Integer)row[0]).intValue());
row = table.addRow("flubber", "row3");
assertEquals(3, ((Integer)row[0]).intValue());
table.reset();
row = table.addRow(Column.AUTO_NUMBER, "row4");
assertEquals(4, ((Integer)row[0]).intValue());
row = table.addRow(Column.AUTO_NUMBER, "row5");
assertEquals(5, ((Integer)row[0]).intValue());
Object[] smallRow = {Column.AUTO_NUMBER};
row = table.addRow(smallRow);
assertNotSame(row, smallRow);
assertEquals(6, ((Integer)row[0]).intValue());
table.reset();
List<? extends Map<String, Object>> expectedRows =
createExpectedTable(
createExpectedRow(
"a", 1,
"b", "row1"),
createExpectedRow(
"a", 2,
"b", "row2"),
createExpectedRow(
"a", 3,
"b", "row3"),
createExpectedRow(
"a", 4,
"b", "row4"),
createExpectedRow(
"a", 5,
"b", "row5"),
createExpectedRow(
"a", 6,
"b", null));
assertTable(expectedRows, table);
}