Search in sources :

Example 31 with SQLServerPreparedStatement

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();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Connection(java.sql.Connection) SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) ResultSet(java.sql.ResultSet) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 32 with SQLServerPreparedStatement

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();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 33 with SQLServerPreparedStatement

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();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Connection(java.sql.Connection) SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) ResultSet(java.sql.ResultSet) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 34 with SQLServerPreparedStatement

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();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 35 with SQLServerPreparedStatement

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();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Connection(java.sql.Connection) SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) ResultSet(java.sql.ResultSet) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)43 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)31 Test (org.junit.jupiter.api.Test)31 ResultSet (java.sql.ResultSet)17 SQLServerDataTable (com.microsoft.sqlserver.jdbc.SQLServerDataTable)13 Connection (java.sql.Connection)9 SQLServerResultSet (com.microsoft.sqlserver.jdbc.SQLServerResultSet)8 SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)6 Statement (java.sql.Statement)5 PreparedStatement (java.sql.PreparedStatement)4 Calendar (java.util.Calendar)4 SQLException (java.sql.SQLException)3 DisplayName (org.junit.jupiter.api.DisplayName)3 SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)2 SQLServerStatement (com.microsoft.sqlserver.jdbc.SQLServerStatement)2 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)2 Properties (java.util.Properties)2 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)1 SQLServerDataSource (com.microsoft.sqlserver.jdbc.SQLServerDataSource)1 SQLServerException (com.microsoft.sqlserver.jdbc.SQLServerException)1