556
556
assertEquals(sb.toString(),toInsert.substring(0,5));
560
public void testBlob() throws SQLException, IOException {
561
connection.createStatement().execute("drop table if exists blobtest");
562
connection.createStatement().execute("create table blobtest (id int not null primary key, strm blob)");
563
PreparedStatement stmt = connection.prepareStatement("insert into blobtest (id, strm) values (?,?)");
564
byte [] theBlob = {1,2,3,4,5,6};
565
InputStream stream = new ByteArrayInputStream(theBlob);
567
stmt.setBlob(2,stream);
569
ResultSet rs = connection.createStatement().executeQuery("select * from blobtest");
571
InputStream readStuff = rs.getBlob("strm").getBinaryStream();
574
while((ch = readStuff.read())!=-1) {
575
assertEquals(theBlob[pos++],ch);
578
readStuff = rs.getBinaryStream("strm");
581
while((ch = readStuff.read())!=-1) {
582
assertEquals(theBlob[pos++],ch);
586
public void testBlobWithLength() throws SQLException, IOException {
587
connection.createStatement().execute("drop table if exists blobtest");
588
connection.createStatement().execute("create table blobtest (id int not null primary key, strm blob)");
589
PreparedStatement stmt = connection.prepareStatement("insert into blobtest (id, strm) values (?,?)");
590
byte [] theBlob = {1,2,3,4,5,6};
591
InputStream stream = new ByteArrayInputStream(theBlob);
593
stmt.setBlob(2,stream,4);
595
ResultSet rs = connection.createStatement().executeQuery("select * from blobtest");
597
InputStream readStuff = rs.getBlob("strm").getBinaryStream();
600
while((ch = readStuff.read())!=-1) {
601
assertEquals(theBlob[pos++],ch);
605
public void testClobWithLength() throws SQLException, IOException {
606
connection.createStatement().execute("drop table if exists clobtest");
607
connection.createStatement().execute("create table clobtest (id int not null primary key, strm text)");
608
PreparedStatement stmt = connection.prepareStatement("insert into clobtest (id, strm) values (?,?)");
609
String clob = "clob";
611
stmt.setClob(2, new StringReader(clob));
613
ResultSet rs = connection.createStatement().executeQuery("select * from clobtest");
615
Reader readStuff = rs.getClob("strm").getCharacterStream();
616
char[] a = new char[4];
618
Assert.assertEquals(new String(a), clob);
622
public void testClob2() throws SQLException, IOException {
623
connection.createStatement().execute("drop table if exists clobtest");
624
connection.createStatement().execute("create table clobtest (id int not null primary key, strm text)");
625
PreparedStatement stmt = connection.prepareStatement("insert into clobtest (id, strm) values (?,?)");
626
Clob clob = connection.createClob();
627
OutputStream ostream = clob.setAsciiStream(1);
628
byte[] bytes = "hello".getBytes();
629
ostream.write(bytes);
631
stmt.setClob(2,clob);
633
ResultSet rs = connection.createStatement().executeQuery("select * from clobtest");
635
Object o = rs.getObject(2);
636
assertTrue(o instanceof String);
637
String s = rs.getString(2);
638
assertTrue(s.equals("hello"));
641
561
public void testEmptyResultSet() throws SQLException {
642
562
connection.createStatement().execute("drop table if exists emptytest");