本文整理匯總了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);
}
}