-
Notifications
You must be signed in to change notification settings - Fork 820
/
PgSQLXMLTest.java
50 lines (41 loc) · 1.38 KB
/
PgSQLXMLTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (c) 2019, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.postgresql.test.TestUtil;
import org.postgresql.test.jdbc2.BaseTest4;
import org.junit.Before;
import org.junit.Test;
import java.io.Writer;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLXML;
import java.sql.Statement;
public class PgSQLXMLTest extends BaseTest4 {
@Override
@Before
public void setUp() throws Exception {
super.setUp();
TestUtil.createTempTable(con, "xmltab","x xml");
}
@Test
public void setCharacterStream() throws Exception {
String exmplar = "<x>value</x>";
SQLXML pgSQLXML = con.createSQLXML();
Writer writer = pgSQLXML.setCharacterStream();
writer.write(exmplar);
PreparedStatement preparedStatement = con.prepareStatement("insert into xmltab values (?)");
preparedStatement.setSQLXML(1,pgSQLXML);
preparedStatement.execute();
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery("select * from xmltab");
assertTrue(rs.next());
SQLXML result = rs.getSQLXML(1);
assertNotNull(result);
assertEquals(exmplar, result.getString());
}
}