use of javax.sql.rowset.serial.SerialBlob in project javautils by jiadongpo.
the class InsertMysql method getInsertMysqlDB.
/**
* 所有的Mysql类型
*/
@Test
public void getInsertMysqlDB() {
String sql = "INSERT INTO mysqldb(id,varcharType,timeType,timestampType,doubleType,decimalType,textType," + "blobType,yearType,enumType,setType,bigintType,bitType,floatType,charType,binaryType,varbinaryType) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Connection connection = null;
PreparedStatement ps = null;
FileInputStream inputStream = null;
try {
// File image = new File("D:/111.bmp");
// inputStream = new FileInputStream(image);
connection = DBUtil.openConnection();
ps = connection.prepareStatement(sql);
for (int i = 1; i < 20; i++) {
// id
ps.setInt(1, RandomUtil.getNum(1, 10000));
// varchar
ps.setString(2, RandomUtil.getCharAndNumr(10));
Time time = new Time(System.currentTimeMillis());
// time
ps.setTime(3, time);
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
// timestamp
ps.setTimestamp(4, timestamp);
// double
ps.setDouble(5, 12.23);
BigDecimal bigDecimal = new BigDecimal(21.21);
// decimal
ps.setBigDecimal(6, bigDecimal);
// text
ps.setString(7, RandomUtil.getCharAndNumr(4));
Blob blob = new SerialBlob("北京欢迎您!".getBytes());
// blob
ps.setBlob(8, blob);
// year
ps.setString(9, "2016");
// emnu
ps.setString(10, "1");
// set
ps.setString(11, "西藏");
// bigint
ps.setInt(12, 13);
// bit
ps.setBoolean(13, true);
// float
ps.setFloat(14, 12);
// char
ps.setString(15, "char value");
// binary
ps.setBytes(16, "北京欢迎您 For binary!".getBytes());
// varbinary
ps.setBytes(17, "北京欢迎您 For varbinary!".getBytes());
ps.executeUpdate();
}
} catch (SQLException e) {
System.out.println("SQLException: - " + e);
} finally {
try {
connection.close();
ps.close();
} catch (SQLException e) {
System.out.println("SQLException Finally: - " + e);
}
}
}
use of javax.sql.rowset.serial.SerialBlob in project ofbiz-framework by apache.
the class EntityTestSuite method testFieldTypes.
/*
* Tests field types.
*/
public void testFieldTypes() throws Exception {
String id = "testFieldTypes";
byte[] b = new byte[100000];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) i;
}
Blob testBlob = new SerialBlob(b);
String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StringBuilder sb = new StringBuilder(alpha.length() * 1000);
for (int i = 0; i < 1000; i++) {
sb.append(alpha);
}
String clobStr = sb.toString();
long currentMillis = System.currentTimeMillis();
Date currentDate = Date.valueOf(new Date(currentMillis).toString());
Time currentTime = Time.valueOf(new Time(currentMillis).toString());
// Different databases have different precision for Timestamps, so
// we will ignore fractional seconds.
Timestamp currentTimestamp = new Timestamp(currentDate.getTime());
BigDecimal fixedPoint = new BigDecimal("999999999999.999999");
// Different databases have different precision for floating
// point types, so we will use a simple decimal number.
Double floatingPoint = 1.0123456789;
Long numeric = Long.MAX_VALUE;
try {
GenericValue testValue = delegator.makeValue("TestFieldType", "testFieldTypeId", id);
testValue.create();
testValue.set("blobField", testBlob);
testValue.set("byteArrayField", b);
testValue.set("objectField", currentTimestamp);
testValue.set("dateField", currentDate);
testValue.set("timeField", currentTime);
testValue.set("dateTimeField", currentTimestamp);
testValue.set("fixedPointField", fixedPoint);
testValue.set("floatingPointField", floatingPoint);
testValue.set("numericField", numeric);
testValue.set("clobField", clobStr);
testValue.store();
testValue = EntityQuery.use(delegator).from("TestFieldType").where("testFieldTypeId", id).queryOne();
assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId"));
Blob blob = (Blob) testValue.get("blobField");
byte[] c = blob.getBytes(1, (int) blob.length());
assertEquals("Byte array read from entity is the same length", b.length, c.length);
for (int i = 0; i < b.length; i++) {
assertEquals("Byte array data[" + i + "]", b[i], c[i]);
}
c = (byte[]) testValue.get("byteArrayField");
assertEquals("Byte array read from entity is the same length", b.length, c.length);
for (int i = 0; i < b.length; i++) {
assertEquals("Byte array data[" + i + "]", b[i], c[i]);
}
assertEquals("objectField", currentTimestamp, testValue.get("objectField"));
assertEquals("dateField", currentDate, testValue.get("dateField"));
assertEquals("timeField", currentTime, testValue.get("timeField"));
assertEquals("dateTimeField", currentTimestamp, testValue.get("dateTimeField"));
assertEquals("fixedPointField", fixedPoint, testValue.get("fixedPointField"));
assertEquals("floatingPointField", floatingPoint, testValue.get("floatingPointField"));
assertEquals("numericField", numeric, testValue.get("numericField"));
assertEquals("clobField", clobStr, testValue.get("clobField"));
testValue.set("blobField", null);
testValue.set("byteArrayField", null);
testValue.set("objectField", null);
testValue.set("dateField", null);
testValue.set("timeField", null);
testValue.set("dateTimeField", null);
testValue.set("fixedPointField", null);
testValue.set("floatingPointField", null);
testValue.set("numericField", null);
testValue.set("clobField", null);
testValue.store();
testValue = EntityQuery.use(delegator).from("TestFieldType").where("testFieldTypeId", id).queryOne();
assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId"));
assertNull("blobField null", testValue.get("blobField"));
assertNull("byteArrayField null", testValue.get("byteArrayField"));
assertNull("objectField null", testValue.get("objectField"));
assertNull("dateField null", testValue.get("dateField"));
assertNull("timeField null", testValue.get("timeField"));
assertNull("dateTimeField null", testValue.get("dateTimeField"));
assertNull("fixedPointField null", testValue.get("fixedPointField"));
assertNull("floatingPointField null", testValue.get("floatingPointField"));
assertNull("numericField null", testValue.get("numericField"));
assertNull("clobField null", testValue.get("clobField"));
} finally {
// Remove all our newly inserted values.
List<GenericValue> values = EntityQuery.use(delegator).from("TestFieldType").queryList();
delegator.removeAll(values);
}
}
use of javax.sql.rowset.serial.SerialBlob in project teiid by teiid.
the class StringAgg method getResult.
/**
* @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext)
*/
public Object getResult(CommandContext commandContext) throws TeiidProcessingException {
if (this.result == null) {
this.result = buildResult(commandContext);
}
try {
this.result.getWriter().close();
FileStoreOutputStream fs = this.result.getOuputStream();
fs.close();
if (binary) {
if (fs.bytesWritten()) {
return new BlobType(new BlobImpl(result));
}
return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount())));
}
if (fs.bytesWritten()) {
return new ClobType(new ClobImpl(result, -1));
}
return new ClobType(new ClobImpl(new String(Arrays.copyOf(fs.getBuffer(), fs.getCount()), Streamable.ENCODING)));
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
} catch (SQLException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
}
}
use of javax.sql.rowset.serial.SerialBlob in project teiid by teiid.
the class TextAgg method getResult.
/**
* @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext)
*/
public Object getResult(CommandContext commandContext) throws TeiidProcessingException {
if (this.result == null) {
this.result = buildResult(commandContext);
}
try {
FileStoreOutputStream fs = this.result.getOuputStream();
fs.close();
if (fs.bytesWritten()) {
return new BlobType(new BlobImpl(result));
}
return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount())));
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
} catch (SQLException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
}
}
use of javax.sql.rowset.serial.SerialBlob in project teiid by teiid.
the class TestXMLSystemFunctions method helpTestJson.
private void helpTestJson(String json, String rootName, String expected) throws SQLException, TeiidComponentException, TeiidProcessingException, SerialException, IOException {
CommandContext cc = new CommandContext();
cc.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
SQLXML xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialClob(json.toCharArray()));
assertEquals(expected, xml.getString());
xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialBlob(json.getBytes(Charset.forName("UTF-8"))));
assertEquals(expected, xml.getString());
xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialBlob(json.getBytes(Charset.forName("UTF-32BE"))));
assertEquals(expected, xml.getString());
}
Aggregations