Java Code Examples for java.sql.CallableStatement.executeUpdate()

The following are Jave code examples for showing how to use executeUpdate() of the java.sql.CallableStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: the-vigilantes   File: CallableStatementRegressionTest.java   Source Code and License Vote up 8 votes
public void testBug35199() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createFunction("test_function", "(a varchar(40), b bigint(20), c varchar(80)) RETURNS bigint(20) LANGUAGE SQL DETERMINISTIC "
            + "MODIFIES SQL DATA COMMENT 'bbb' BEGIN RETURN 1; END; ");

    CallableStatement callable = null;
    try {
        callable = this.conn.prepareCall("{? = call test_function(?,101,?)}");
        callable.registerOutParameter(1, Types.BIGINT);

        callable.setString(2, "FOO");
        callable.setString(3, "BAR");
        callable.executeUpdate();
    } finally {
        if (callable != null) {
            callable.close();
        }
    }
}
 
Example 2
Project: the-vigilantes   File: CallableStatementRegressionTest.java   Source Code and License Vote up 6 votes
/**
 * Tests fix for BUG#25379 - INOUT parameters in CallableStatements get
 * doubly-escaped.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug25379() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return;
    }

    createTable("testBug25379", "(col char(40))");

    createProcedure("sp_testBug25379", "(INOUT invalue char(255))\nBEGIN" + "\ninsert into testBug25379(col) values(invalue);\nEND");

    CallableStatement cstmt = this.conn.prepareCall("{call sp_testBug25379(?)}");
    cstmt.setString(1, "'john'");
    cstmt.executeUpdate();
    assertEquals("'john'", cstmt.getString(1));
    assertEquals("'john'", getSingleValue("testBug25379", "col", "").toString());
}
 
Example 3
Project: OpenVertretung   File: CallableStatementRegressionTest.java   Source Code and License Vote up 6 votes
/**
 * Tests fix for BUG#25379 - INOUT parameters in CallableStatements get
 * doubly-escaped.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug25379() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return;
    }

    createTable("testBug25379", "(col char(40))");

    createProcedure("sp_testBug25379", "(INOUT invalue char(255))\nBEGIN" + "\ninsert into testBug25379(col) values(invalue);\nEND");

    CallableStatement cstmt = this.conn.prepareCall("{call sp_testBug25379(?)}");
    cstmt.setString(1, "'john'");
    cstmt.executeUpdate();
    assertEquals("'john'", cstmt.getString(1));
    assertEquals("'john'", getSingleValue("testBug25379", "col", "").toString());
}
 
Example 4
Project: OpenVertretung   File: CallableStatementRegressionTest.java   Source Code and License Vote up 6 votes
public void testBug35199() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createFunction("test_function", "(a varchar(40), b bigint(20), c varchar(80)) RETURNS bigint(20) LANGUAGE SQL DETERMINISTIC "
            + "MODIFIES SQL DATA COMMENT 'bbb' BEGIN RETURN 1; END; ");

    CallableStatement callable = null;
    try {
        callable = this.conn.prepareCall("{? = call test_function(?,101,?)}");
        callable.registerOutParameter(1, Types.BIGINT);

        callable.setString(2, "FOO");
        callable.setString(3, "BAR");
        callable.executeUpdate();
    } finally {
        if (callable != null) {
            callable.close();
        }
    }
}
 
Example 5
Project: ProyectoPacientes   File: CallableStatementRegressionTest.java   Source Code and License Vote up 6 votes
/**
 * Tests fix for BUG#25379 - INOUT parameters in CallableStatements get
 * doubly-escaped.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug25379() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return;
    }

    createTable("testBug25379", "(col char(40))");

    createProcedure("sp_testBug25379", "(INOUT invalue char(255))\nBEGIN" + "\ninsert into testBug25379(col) values(invalue);\nEND");

    CallableStatement cstmt = this.conn.prepareCall("{call sp_testBug25379(?)}");
    cstmt.setString(1, "'john'");
    cstmt.executeUpdate();
    assertEquals("'john'", cstmt.getString(1));
    assertEquals("'john'", getSingleValue("testBug25379", "col", "").toString());
}
 
Example 6
Project: BibliotecaPS   File: CallableStatementRegressionTest.java   Source Code and License Vote up 6 votes
public void testBug35199() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createFunction("test_function", "(a varchar(40), b bigint(20), c varchar(80)) RETURNS bigint(20) LANGUAGE SQL DETERMINISTIC "
            + "MODIFIES SQL DATA COMMENT 'bbb' BEGIN RETURN 1; END; ");

    CallableStatement callable = null;
    try {
        callable = this.conn.prepareCall("{? = call test_function(?,101,?)}");
        callable.registerOutParameter(1, Types.BIGINT);

        callable.setString(2, "FOO");
        callable.setString(3, "BAR");
        callable.executeUpdate();
    } finally {
        if (callable != null) {
            callable.close();
        }
    }
}
 
Example 7
Project: BibliotecaPS   File: CallableStatementRegressionTest.java   Source Code and License Vote up 6 votes
/**
 * Tests fix for BUG#25379 - INOUT parameters in CallableStatements get
 * doubly-escaped.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug25379() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return;
    }

    createTable("testBug25379", "(col char(40))");

    createProcedure("sp_testBug25379", "(INOUT invalue char(255))\nBEGIN" + "\ninsert into testBug25379(col) values(invalue);\nEND");

    CallableStatement cstmt = this.conn.prepareCall("{call sp_testBug25379(?)}");
    cstmt.setString(1, "'john'");
    cstmt.executeUpdate();
    assertEquals("'john'", cstmt.getString(1));
    assertEquals("'john'", getSingleValue("testBug25379", "col", "").toString());
}
 
Example 8
Project: tqdev-metrics   File: InstrumentedDataSourceTest.java   Source Code and License Vote up 6 votes
/**
 * Should measure callable statement.
 *
 * @throws SQLException
 *             the SQL exception
 */
@Test
public void shouldMeasureCallableStatement() throws SQLException {
	CallableStatement statements[] = { dataSource.getConnection().prepareCall("select"),
			dataSource.getConnection().prepareCall("select", 1, 1),
			dataSource.getConnection().prepareCall("select", 1, 1, 1) };
	for (CallableStatement statement : statements) {
		statement.execute();
		statement.executeQuery();
		statement.executeUpdate();
		statement.executeLargeUpdate();
		statement.addBatch();
		statement.executeBatch();
		statement.executeLargeBatch();
	}
	assertThat(registry.get("jdbc.Statement.Invocations", "select")).isEqualTo(1L * 6 * statements.length);
	assertThat(registry.get("jdbc.Statement.Durations", "select")).isEqualTo(123456789L * 6 * statements.length);
}
 
Example 9
Project: the-vigilantes   File: StatementRegressionTest.java   Source Code and License Vote up 5 votes
public void testMoreLanceBugs() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("Bit_Tab", "( `MAX_VAL` BIT default NULL, `MIN_VAL` BIT default NULL, `NULL_VAL` BIT default NULL) DEFAULT CHARSET=latin1", "InnoDB");
    // this.stmt.execute("insert into Bit_Tab values(null,0,null)");
    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT) "
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end ");

    Boolean minBooleanVal;
    Boolean oRetVal;
    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    cstmt.executeUpdate();

    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    assertEquals(minBooleanVal, oRetVal);
}
 
Example 10
Project: OpenVertretung   File: StatementRegressionTest.java   Source Code and License Vote up 5 votes
public void testMoreLanceBugs() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("Bit_Tab", "( `MAX_VAL` BIT default NULL, `MIN_VAL` BIT default NULL, `NULL_VAL` BIT default NULL) DEFAULT CHARSET=latin1", "InnoDB");
    // this.stmt.execute("insert into Bit_Tab values(null,0,null)");
    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT) "
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end ");

    Boolean minBooleanVal;
    Boolean oRetVal;
    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    cstmt.executeUpdate();

    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    assertEquals(minBooleanVal, oRetVal);
}
 
Example 11
Project: ProyectoPacientes   File: StatementRegressionTest.java   Source Code and License Vote up 5 votes
public void testMoreLanceBugs() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("Bit_Tab", "( `MAX_VAL` BIT default NULL, `MIN_VAL` BIT default NULL, `NULL_VAL` BIT default NULL) DEFAULT CHARSET=latin1", "InnoDB");
    // this.stmt.execute("insert into Bit_Tab values(null,0,null)");
    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT) "
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end ");

    Boolean minBooleanVal;
    Boolean oRetVal;
    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    cstmt.executeUpdate();

    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    assertEquals(minBooleanVal, oRetVal);
}
 
Example 12
Project: AnyMall   File: PooledConnection.java   Source Code and License Vote up 5 votes
public int execCallUpdate(String sql, Object[] params) throws SQLException {
	CallableStatement call = conn.prepareCall(sql);
	for (int i = 0; i < params.length; i++) {
		call.setObject(i + 1, params[0]);
	}
	return call.executeUpdate();
}
 
Example 13
Project: BibliotecaPS   File: StatementRegressionTest.java   Source Code and License Vote up 5 votes
public void testMoreLanceBugs() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("Bit_Tab", "( `MAX_VAL` BIT default NULL, `MIN_VAL` BIT default NULL, `NULL_VAL` BIT default NULL) DEFAULT CHARSET=latin1", "InnoDB");
    // this.stmt.execute("insert into Bit_Tab values(null,0,null)");
    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT) "
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end ");

    Boolean minBooleanVal;
    Boolean oRetVal;
    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    cstmt.executeUpdate();

    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    assertEquals(minBooleanVal, oRetVal);
}
 
Example 14
Project: the-vigilantes   File: CallableStatementRegressionTest.java   Source Code and License Vote up 4 votes
/**
 * Tests fix for BUG#25715 - CallableStatements with OUT/INOUT parameters
 * that are "binary" have extra 7 bytes (which happens to be the _binary
 * introducer!)
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug25715() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return; // no stored procs
    }

    createProcedure("spbug25715", "(INOUT mblob MEDIUMBLOB) BEGIN SELECT 1 FROM DUAL WHERE 1=0;\nEND");
    CallableStatement cstmt = null;

    try {
        cstmt = this.conn.prepareCall("{call spbug25715(?)}");

        byte[] buf = new byte[65];
        for (int i = 0; i < 65; i++) {
            buf[i] = 1;
        }
        int il = buf.length;

        int[] typesToTest = new int[] { Types.BIT, Types.BINARY, Types.BLOB, Types.JAVA_OBJECT, Types.LONGVARBINARY, Types.VARBINARY };

        for (int i = 0; i < typesToTest.length; i++) {

            cstmt.setBinaryStream("mblob", new ByteArrayInputStream(buf), buf.length);
            cstmt.registerOutParameter("mblob", typesToTest[i]);

            cstmt.executeUpdate();

            InputStream is = cstmt.getBlob("mblob").getBinaryStream();
            ByteArrayOutputStream bOut = new ByteArrayOutputStream();

            int bytesRead = 0;
            byte[] readBuf = new byte[256];

            while ((bytesRead = is.read(readBuf)) != -1) {
                bOut.write(readBuf, 0, bytesRead);
            }

            byte[] fromSelectBuf = bOut.toByteArray();

            int ol = fromSelectBuf.length;

            assertEquals(il, ol);
        }

        cstmt.close();
    } finally {

        if (cstmt != null) {
            cstmt.close();
        }
    }

}
 
Example 15
Project: the-vigilantes   File: CallableStatementRegressionTest.java   Source Code and License Vote up 4 votes
public void testBitSp() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("`Bit_Tab`", "( `MAX_VAL` tinyint(1) default NULL, `MIN_VAL` tinyint(1) default NULL, `NULL_VAL` tinyint(1) default NULL)");

    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT)"
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end");

    Boolean minBooleanVal;
    Boolean oRetVal;

    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    //String sMaxBooleanVal = "1";
    // sMaxBooleanVal = "true";
    //Boolean bool = Boolean.valueOf("true");
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    System.out.println("register the output parameters");
    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    System.out.println("execute the procedure");
    cstmt.executeUpdate();

    System.out.println("invoke getBoolean method");
    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    if (oRetVal.equals(minBooleanVal)) {
        System.out.println("getBoolean returns the Minimum value ");
    } else {
        System.out.println("getBoolean() did not return the Minimum value, getBoolean Failed!");

    }
}
 
Example 16
Project: eXperDB-DB2PG   File: DataAdapter.java   Source Code and License Vote up 4 votes
/************************************************************
 * Call Procedure(One only Out Parameter)
 ************************************************************/
public int CallProcedure(String sql, List<CallableParameter> binds) throws Exception{		
	CallableStatement cStmt = null;
	try{
		if (conn == null) {
			conn = DBCPPoolManager.getConnection(PoolName);
			
		}

		cStmt = conn.prepareCall(sql);
		int retIdx = 0;
		if (binds != null) {
			for (int i = 1; i<= binds.size(); i++) {
				if (binds.get(i - 1).getType() == CallableType.IN){
					cStmt.setObject(i, binds.get(i - 1).getValue());
				}else{
					retIdx = i;
					cStmt.registerOutParameter(i, binds.get(i - 1).getOutValueType());
				}
				
			}	
		}
		
		int ret = cStmt.executeUpdate();
		
		if (conn != null && IsTransaction == false) {
			conn.commit();
		}
		
		if (retIdx != 0){
			binds.get(retIdx).setValue(cStmt.getObject(retIdx));
		}
		
		return ret;
	}catch(SQLException e){
		LogUtils.error(CommonUtil.getStackTrace(e.getNextException()),DataAdapter.class);
		throw e;
	}finally {
		CloseConn(cStmt);
	}
}
 
Example 17
Project: OpenVertretung   File: CallableStatementRegressionTest.java   Source Code and License Vote up 4 votes
/**
 * Tests fix for BUG#25715 - CallableStatements with OUT/INOUT parameters
 * that are "binary" have extra 7 bytes (which happens to be the _binary
 * introducer!)
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug25715() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return; // no stored procs
    }

    createProcedure("spbug25715", "(INOUT mblob MEDIUMBLOB) BEGIN SELECT 1 FROM DUAL WHERE 1=0;\nEND");
    CallableStatement cstmt = null;

    try {
        cstmt = this.conn.prepareCall("{call spbug25715(?)}");

        byte[] buf = new byte[65];
        for (int i = 0; i < 65; i++) {
            buf[i] = 1;
        }
        int il = buf.length;

        int[] typesToTest = new int[] { Types.BIT, Types.BINARY, Types.BLOB, Types.JAVA_OBJECT, Types.LONGVARBINARY, Types.VARBINARY };

        for (int i = 0; i < typesToTest.length; i++) {

            cstmt.setBinaryStream("mblob", new ByteArrayInputStream(buf), buf.length);
            cstmt.registerOutParameter("mblob", typesToTest[i]);

            cstmt.executeUpdate();

            InputStream is = cstmt.getBlob("mblob").getBinaryStream();
            ByteArrayOutputStream bOut = new ByteArrayOutputStream();

            int bytesRead = 0;
            byte[] readBuf = new byte[256];

            while ((bytesRead = is.read(readBuf)) != -1) {
                bOut.write(readBuf, 0, bytesRead);
            }

            byte[] fromSelectBuf = bOut.toByteArray();

            int ol = fromSelectBuf.length;

            assertEquals(il, ol);
        }

        cstmt.close();
    } finally {

        if (cstmt != null) {
            cstmt.close();
        }
    }

}
 
Example 18
Project: OpenVertretung   File: CallableStatementRegressionTest.java   Source Code and License Vote up 4 votes
public void testBitSp() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("`Bit_Tab`", "( `MAX_VAL` tinyint(1) default NULL, `MIN_VAL` tinyint(1) default NULL, `NULL_VAL` tinyint(1) default NULL)");

    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT)"
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end");

    Boolean minBooleanVal;
    Boolean oRetVal;

    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    //String sMaxBooleanVal = "1";
    // sMaxBooleanVal = "true";
    //Boolean bool = Boolean.valueOf("true");
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    System.out.println("register the output parameters");
    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    System.out.println("execute the procedure");
    cstmt.executeUpdate();

    System.out.println("invoke getBoolean method");
    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    if (oRetVal.equals(minBooleanVal)) {
        System.out.println("getBoolean returns the Minimum value ");
    } else {
        System.out.println("getBoolean() did not return the Minimum value, getBoolean Failed!");

    }
}
 
Example 19
Project: ProyectoPacientes   File: CallableStatementRegressionTest.java   Source Code and License Vote up 4 votes
/**
 * Tests fix for BUG#25715 - CallableStatements with OUT/INOUT parameters
 * that are "binary" have extra 7 bytes (which happens to be the _binary
 * introducer!)
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug25715() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return; // no stored procs
    }

    createProcedure("spbug25715", "(INOUT mblob MEDIUMBLOB) BEGIN SELECT 1 FROM DUAL WHERE 1=0;\nEND");
    CallableStatement cstmt = null;

    try {
        cstmt = this.conn.prepareCall("{call spbug25715(?)}");

        byte[] buf = new byte[65];
        for (int i = 0; i < 65; i++) {
            buf[i] = 1;
        }
        int il = buf.length;

        int[] typesToTest = new int[] { Types.BIT, Types.BINARY, Types.BLOB, Types.JAVA_OBJECT, Types.LONGVARBINARY, Types.VARBINARY };

        for (int i = 0; i < typesToTest.length; i++) {

            cstmt.setBinaryStream("mblob", new ByteArrayInputStream(buf), buf.length);
            cstmt.registerOutParameter("mblob", typesToTest[i]);

            cstmt.executeUpdate();

            InputStream is = cstmt.getBlob("mblob").getBinaryStream();
            ByteArrayOutputStream bOut = new ByteArrayOutputStream();

            int bytesRead = 0;
            byte[] readBuf = new byte[256];

            while ((bytesRead = is.read(readBuf)) != -1) {
                bOut.write(readBuf, 0, bytesRead);
            }

            byte[] fromSelectBuf = bOut.toByteArray();

            int ol = fromSelectBuf.length;

            assertEquals(il, ol);
        }

        cstmt.close();
    } finally {

        if (cstmt != null) {
            cstmt.close();
        }
    }

}
 
Example 20
Project: ProyectoPacientes   File: CallableStatementRegressionTest.java   Source Code and License Vote up 4 votes
public void testBitSp() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("`Bit_Tab`", "( `MAX_VAL` tinyint(1) default NULL, `MIN_VAL` tinyint(1) default NULL, `NULL_VAL` tinyint(1) default NULL)");

    createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT)"
            + "begin select MAX_VAL, MIN_VAL, NULL_VAL  into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end");

    Boolean minBooleanVal;
    Boolean oRetVal;

    String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
    //String sMaxBooleanVal = "1";
    // sMaxBooleanVal = "true";
    //Boolean bool = Boolean.valueOf("true");
    String Min_Insert = "insert into Bit_Tab values(1,0,null)";
    // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
    CallableStatement cstmt;

    this.stmt.executeUpdate("delete from Bit_Tab");
    this.stmt.executeUpdate(Min_Insert);
    cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");

    System.out.println("register the output parameters");
    cstmt.registerOutParameter(1, java.sql.Types.BIT);
    cstmt.registerOutParameter(2, java.sql.Types.BIT);
    cstmt.registerOutParameter(3, java.sql.Types.BIT);

    System.out.println("execute the procedure");
    cstmt.executeUpdate();

    System.out.println("invoke getBoolean method");
    boolean bRetVal = cstmt.getBoolean(2);
    oRetVal = new Boolean(bRetVal);
    minBooleanVal = new Boolean("false");
    this.rs = this.stmt.executeQuery(Min_Val_Query);
    if (oRetVal.equals(minBooleanVal)) {
        System.out.println("getBoolean returns the Minimum value ");
    } else {
        System.out.println("getBoolean() did not return the Minimum value, getBoolean Failed!");

    }
}