本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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);
}
}