use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testXML.
/**
* Test xml support
*
* @throws SQLException
*/
@Test
public void testXML() throws SQLException {
createTables("xml");
createTVPS("xml");
value = "<vx53_e>Variable E</vx53_e>" + "<vx53_f>Variable F</vx53_f>" + "<doc>API<!-- comments --></doc>" + "<doc>The following are Japanese chars.</doc>" + "<doc> Some UTF-8 encoded characters: �������</doc>";
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.SQLXML);
tvp.addRow(value);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
Connection con = DriverManager.getConnection(connectionString);
ResultSet rs = con.createStatement().executeQuery("select * from " + table);
while (rs.next()) assertEquals(rs.getString(1), value);
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testLongVarchar.
/**
* Test a longvarchar support
*
* @throws SQLException
*/
@Test
public void testLongVarchar() throws SQLException {
createTables("varchar(max)");
createTVPS("varchar(max)");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 9000; i++) buffer.append("a");
value = buffer.toString();
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.LONGVARCHAR);
tvp.addRow(value);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
rs = conn.createStatement().executeQuery("select * from " + table);
while (rs.next()) {
assertEquals(rs.getString(1), value);
}
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testText.
/**
* Test text support
*
* @throws SQLException
*/
@Test
public void testText() throws SQLException {
createTables("text");
createTVPS("text");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 9000; i++) buffer.append("a");
value = buffer.toString();
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.LONGVARCHAR);
tvp.addRow(value);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
Connection con = DriverManager.getConnection(connectionString);
ResultSet rs = con.createStatement().executeQuery("select * from " + table);
while (rs.next()) assertEquals(rs.getString(1), value);
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testSmallDateTime.
/**
* Test a smalldatetime support
*
* @throws SQLException
*/
@Test
public void testSmallDateTime() throws SQLException {
createTables("smalldatetime");
createTVPS("smalldatetime");
java.sql.Timestamp value = java.sql.Timestamp.valueOf("2007-09-23 10:10:10.123");
java.sql.Timestamp returnValue = java.sql.Timestamp.valueOf("2007-09-23 10:10:00.0");
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SMALLDATETIME);
tvp.addRow(value);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
rs = conn.createStatement().executeQuery("select * from " + table);
while (rs.next()) {
assertEquals(((SQLServerResultSet) rs).getSmallDateTime(1), returnValue);
}
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testnText.
/**
* Test ntext support
*
* @throws SQLException
*/
@Test
public void testnText() throws SQLException {
createTables("ntext");
createTVPS("ntext");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 9000; i++) buffer.append("س");
value = buffer.toString();
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.LONGNVARCHAR);
tvp.addRow(value);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
Connection con = DriverManager.getConnection(connectionString);
ResultSet rs = con.createStatement().executeQuery("select * from " + table);
while (rs.next()) assertEquals(rs.getString(1), value);
if (null != pstmt) {
pstmt.close();
}
}
Aggregations