當前位置: 首頁>>代碼示例>>Java>>正文


Java CallableStatement.setFloat方法代碼示例

本文整理匯總了Java中java.sql.CallableStatement.setFloat方法的典型用法代碼示例。如果您正苦於以下問題:Java CallableStatement.setFloat方法的具體用法?Java CallableStatement.setFloat怎麽用?Java CallableStatement.setFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.CallableStatement的用法示例。


在下文中一共展示了CallableStatement.setFloat方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBug78961

import java.sql.CallableStatement; //導入方法依賴的package包/類
/**
 * Tests fix for Bug#78961 - Can't call MySQL procedure with InOut parameters in Fabric environment.
 * 
 * Although this is a Fabric related bug we are able reproduce it using a couple of multi-host connections.
 */
public void testBug78961() throws Exception {
    createProcedure("testBug78961", "(IN c1 FLOAT, IN c2 FLOAT, OUT h FLOAT, INOUT t FLOAT) BEGIN SET h = SQRT(c1 * c1 + c2 * c2); SET t = t + h; END;");

    Connection highLevelConn = getLoadBalancedConnection(null);
    assertTrue(highLevelConn.getClass().getName().startsWith("com.sun.proxy") || highLevelConn.getClass().getName().startsWith("$Proxy"));

    Connection lowLevelConn = getMasterSlaveReplicationConnection(null);
    // This simulates the behavior from Fabric connections that are causing the problem.
    ((ReplicationConnection) lowLevelConn).setProxy((MySQLConnection) highLevelConn);

    CallableStatement cstmt = lowLevelConn.prepareCall("{CALL testBug78961 (?, ?, ?, ?)}");
    cstmt.setFloat(1, 3.0f);
    cstmt.setFloat(2, 4.0f);
    cstmt.setFloat(4, 5.0f);
    cstmt.registerOutParameter(3, Types.FLOAT);
    cstmt.registerOutParameter(4, Types.FLOAT);
    cstmt.execute();

    assertEquals(5.0f, cstmt.getFloat(3));
    assertEquals(10.0f, cstmt.getFloat(4));
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:27,代碼來源:StatementRegressionTest.java

示例2: callFunction

import java.sql.CallableStatement; //導入方法依賴的package包/類
private void callFunction(CallableStatement cStmt, Connection c) throws SQLException {
    cStmt = c.prepareCall("{? = CALL testbug61203fn(?)}");
    cStmt.registerOutParameter(1, Types.INTEGER);
    cStmt.setFloat(2, 2);
    cStmt.execute();
    assertEquals(2f, cStmt.getInt(1), .001);
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:8,代碼來源:MetaDataRegressionTest.java

示例3: callProcedure

import java.sql.CallableStatement; //導入方法依賴的package包/類
private void callProcedure(CallableStatement cStmt, Connection c) throws SQLException {
    cStmt = c.prepareCall("{CALL testbug61203pr(?,?,?)}");
    cStmt.setFloat(1, 2);
    cStmt.setInt(2, 1);
    cStmt.setInt(3, 1);
    cStmt.registerOutParameter(1, Types.INTEGER);
    cStmt.execute();
    assertEquals(2f, cStmt.getInt(1), .001);
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:10,代碼來源:MetaDataRegressionTest.java

示例4: buildProcedureCallableStatement

import java.sql.CallableStatement; //導入方法依賴的package包/類
private static StatementWrapper buildProcedureCallableStatement(String sql,Map<String, Object> pmap,Connection conn){
	try {
		Map<String,Object> paramMap=new LinkedHashMap<String,Object>();
		int leftParnPos=sql.indexOf("(");
		int rightParnPos=sql.indexOf(")");
		String paramStr="";
		if(leftParnPos>-1 && rightParnPos>-1){
			paramStr=sql.substring(leftParnPos+1,rightParnPos);				
		}
		int oracleCursorIndex=-1,paramIndex=0;
		String[] str=paramStr.split(",");
		for(String param:str){
			paramIndex++;
			param=param.trim();
			if(param.toLowerCase().equals("oracle")){
				sql=sql.replaceFirst(param, "?");
				oracleCursorIndex=paramIndex;
				continue;
			}else if(!param.startsWith(":")){
				continue;
			}
			sql=sql.replaceFirst(param, "?");
			String paramName=param.substring(1,param.length());
			Object paramValue=pmap.get(paramName);
			paramMap.put(paramName, (paramValue==null ? "" : paramValue));
		}
		String procedure="{"+sql+"}";
		CallableStatement cs= conn.prepareCall(procedure);
		int index=1;
		for(String name:paramMap.keySet()){
			Object value=paramMap.get(name);
			if(value instanceof String){
				cs.setString(index,(String)value);									
			}else if(value instanceof Date){
				Date date=(Date)value;
				cs.setDate(index, new java.sql.Date(date.getTime()));
			}else if(value instanceof Integer){
				cs.setInt(index, (Integer)value);
			}else if(value instanceof Float){
				cs.setFloat(index, (Float)value);
			}else if(value instanceof Double){
				cs.setDouble(index, (Double)value);
			}else{
				cs.setObject(index, value);
			}
			index++;
		}
		if(oracleCursorIndex>-1){
			cs.registerOutParameter(oracleCursorIndex, -10);
		}
		return new StatementWrapper(cs,oracleCursorIndex);
	} catch (SQLException e) {
		throw new ReportException(e);
	}
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:56,代碼來源:ProcedureUtils.java


注:本文中的java.sql.CallableStatement.setFloat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。