本文整理匯總了Java中java.sql.PreparedStatement.setFloat方法的典型用法代碼示例。如果您正苦於以下問題:Java PreparedStatement.setFloat方法的具體用法?Java PreparedStatement.setFloat怎麽用?Java PreparedStatement.setFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.setFloat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: bindArgs
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/**
* Binds arguments to prepared statement
* @param stmt the prepared statement reference
* @return the same as arg
* @throws SQLException if binding fails
*/
private PreparedStatement bindArgs(PreparedStatement stmt) throws SQLException {
for (int i=0; i<args.length; ++i) {
final Object value = args[i];
if (value instanceof Boolean) stmt.setBoolean(i+1, (Boolean)value);
else if (value instanceof Short) stmt.setShort(i+1, (Short)value);
else if (value instanceof Integer) stmt.setInt(i+1, (Integer)value);
else if (value instanceof Float) stmt.setFloat(i+1, (Float)value);
else if (value instanceof Long) stmt.setLong(i+1, (Long)value);
else if (value instanceof Double) stmt.setDouble(i+1, (Double)value);
else if (value instanceof String) stmt.setString(i+1, (String)value);
else if (value instanceof java.sql.Date) stmt.setDate(i+1, (java.sql.Date)value);
else if (value instanceof Timestamp) stmt.setTimestamp(i+1, (Timestamp)value);
else if (value instanceof LocalDate) stmt.setDate(i + 1, java.sql.Date.valueOf((LocalDate)value));
else if (value instanceof LocalTime) stmt.setTime(i+1, Time.valueOf((LocalTime)value));
else if (value instanceof LocalDateTime) stmt.setTimestamp(i+1, Timestamp.valueOf((LocalDateTime)value));
else if (value instanceof ZonedDateTime) {
final ZonedDateTime zonedDateTime = (ZonedDateTime)value;
final LocalDateTime dateTime = zonedDateTime.toLocalDateTime();
stmt.setTimestamp(i+1, Timestamp.valueOf(dateTime));
} else {
throw new RuntimeException("Unsupported argument, cannot be bound to SQL statement: " + value);
}
}
return stmt;
}
示例2: insertValuesIntoStatement
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
public PreparedStatement insertValuesIntoStatement(PreparedStatement statement, String[] values, String[] valueTypes, int offset) throws NumberFormatException, SQLException {
for (int i = 0; i < values.length; i++) {
String valueType = valueTypes[i + offset].toLowerCase();
if ((values[i] == null) || (values[i].equals(""))) {
if (valueType.contains("long") || valueType.contains("big") || valueType.contains("int8"))
statement.setNull(i + 1, java.sql.Types.BIGINT);
else if (valueType.contains("int") || valueType.contains("serial"))
statement.setNull(i + 1, java.sql.Types.INTEGER);
else if (valueType.contains("float") || valueType.contains("numeric") || valueType.contains("decimal") || valueType.contains("real") || valueType.contains("precision"))
statement.setNull(i + 1, java.sql.Types.FLOAT);
else if (valueType.contains("bool"))
statement.setNull(i + 1, java.sql.Types.BOOLEAN);
else if (valueType.contains("date"))
statement.setNull(i + 1, java.sql.Types.DATE);
else
statement.setNull(i + 1, java.sql.Types.VARCHAR);
}
else {
if (valueType.contains("long") || valueType.contains("big") || valueType.contains("int8"))
statement.setLong(i + 1, Long.valueOf(values[i]).longValue());
else if (valueType.contains("int") || valueType.contains("serial"))
statement.setInt(i + 1, Integer.valueOf(values[i]).intValue());
else if (valueType.contains("float") || valueType.contains("numeric") || valueType.contains("decimal") || valueType.contains("real") || valueType.contains("precision"))
statement.setFloat(i + 1, Float.valueOf(values[i]).shortValue());
else if (valueType.contains("bool"))
statement.setBoolean(i + 1, Boolean.valueOf(values[i]).booleanValue());
else if (valueType.contains("date"))
statement.setDate(i + 1, Date.valueOf(values[i]));
else
statement.setString(i + 1, values[i]);
}
}
return statement;
}
開發者ID:HPI-Information-Systems,項目名稱:AdvancedDataProfilingSeminar,代碼行數:37,代碼來源:PostgreSQLDataAccessObject.java
示例3: appendValue
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void appendValue(PreparedStatement statement, int index) throws SQLException {
index = index + 1;
if (dataType == DataType.BOOLEAN) {
statement.setBoolean(index, dataValue.equals("1"));
} else if (dataType == DataType.INTEGER) {
statement.setInt(index, Integer.parseInt(dataValue));
} else if (dataType == DataType.STRING) {
statement.setString(index, dataValue);
} else if (dataType == DataType.DOUBLE) {
statement.setDouble(index, Double.parseDouble(dataValue));
} else if (dataType == DataType.FLOAT) {
statement.setFloat(index, Float.parseFloat(dataValue));
} else if (dataType == DataType.LONG) {
statement.setLong(index, Long.parseLong(dataValue));
}
}
示例4: createItem
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void createItem(ItemCreation i) {
Connection conn = null;
try {
conn = MysqlDAO.getInstance().connect();
PreparedStatement statement = conn.prepareStatement(""+ "INSERT INTO `item` (`ID`, `name`, `dop`, `price`, `notes`) " + "VALUES (?, ?, ?, ?, ?)");
statement.setInt(1, i.getID());
statement.setString(2, i.getName());
statement.setString(3, i.getPurchasedate());
statement.setFloat(4, i.getPrice());
statement.setString(5, i.getNotes());
statement.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(MysqlDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
MysqlDAO.getInstance().closeConnection(conn);
}
}
示例5: setLinkAttr
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private void setLinkAttr(Edge e, String attr, PreparedStatement st, int index) throws SQLException {
if(attr.compareToIgnoreCase("id_origin") == 0) {
st.setInt(index, e.getSource().getId() );
} else if(attr.compareToIgnoreCase("id_dest") == 0) {
st.setInt(index, e.getTarget().getId() );
} else if(attr.compareToIgnoreCase("weight") == 0) {
st.setFloat(index, (float)e.getWeight() );
} else if(attr.compareToIgnoreCase("label") == 0) {
st.setString(index, e.getLabel() );
} else if(attr.compareToIgnoreCase("width") == 0) {
st.setFloat(index, (float)e.getWidth() );
} else if(attr.compareToIgnoreCase("color") == 0) {
st.setString(index, "" + ((double)e.getColor().getRed()/256.d)
+","+((double)e.getColor().getGreen()/256.d)
+","+((double)e.getColor().getBlue()/256.d));
} else if(attr.compareToIgnoreCase("var1") == 0) {
st.setString(index, e.getVar1() );
} else if(attr.compareToIgnoreCase("var2") == 0) {
st.setString(index, e.getVar2() );
} else if(attr.compareToIgnoreCase("hide") == 0) {
st.setBoolean(index, e.isExcluded() );
}
}
示例6: placeOrder
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static boolean placeOrder(String orderId, String customerId, String address, String payMode, String orderData, float amount) {
boolean status = false;
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection(com.sahilsunny.ogo.Main.getDbUri());
PreparedStatement ps = con.prepareStatement("INSERT INTO orders VALUES (?, ?, ?, ?, ?, ?)");
ps.setString(1, orderId);
ps.setString(2, customerId);
ps.setString(3, address);
ps.setString(4, payMode);
ps.setString(5, orderData);
ps.setFloat(6, amount);
int count = ps.executeUpdate();
if (count > 0) {
status = true;
}
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
return status;
}
示例7: setLinkAttr
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private void setLinkAttr(Edge e, String attr, PreparedStatement st, int index) throws SQLException {
if(attr.compareToIgnoreCase("id_origin") == 0) {
st.setInt(index, network.getSource(e).getId() );
} else if(attr.compareToIgnoreCase("id_dest") == 0) {
st.setInt(index, network.getDest(e).getId() );
} else if(attr.compareToIgnoreCase("weight") == 0) {
st.setFloat(index, (float)e.getWeight() );
} else if(attr.compareToIgnoreCase("label") == 0) {
st.setString(index, e.getLabel() );
} else if(attr.compareToIgnoreCase("width") == 0) {
st.setFloat(index, (float)e.getWidth() );
} else if(attr.compareToIgnoreCase("color") == 0) {
st.setString(index, "" + ((double)e.getColor().getRed()/256.d)
+","+((double)e.getColor().getGreen()/256.d)
+","+((double)e.getColor().getBlue()/256.d));
} else if(attr.compareToIgnoreCase("var1") == 0) {
st.setString(index, e.getVar1() );
} else if(attr.compareToIgnoreCase("var2") == 0) {
st.setString(index, e.getVar2() );
} else if(attr.compareToIgnoreCase("hide") == 0) {
st.setBoolean(index, e.isExcluded() );
}
}
示例8: populate
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/**
* set preparedstatement params
*
* @param ps
* @param args
* @return
* @throws SQLException
*/
private void populate(PreparedStatement ps, List<?> args)
throws SQLException {
for (int i = 0; i < args.size(); i++) {
Object o = args.get(i);
if (o instanceof Integer) {
ps.setInt(i + 1, (int) o);
} else if (o instanceof Long) {
ps.setLong(i + 1, (long) o);
} else if (o instanceof String) {
ps.setString(i + 1, (String) o);
} else if (o instanceof Date) {
ps.setDate(i + 1, (Date) o);
} else if (o instanceof Float) {
ps.setFloat(i + 1, (Float) o);
} else if (o instanceof Double) {
ps.setDouble(i + 1, (Double) o);
} else if (o instanceof Date) {
ps.setDate(i + 1, (Date) o);
} else if (o instanceof Timestamp) {
ps.setTimestamp(i + 1, (Timestamp) o);
} else if (o instanceof Descriptors.EnumValueDescriptor) {
ps.setInt(i + 1,
((Descriptors.EnumValueDescriptor) o).getNumber());
} else if(o instanceof Boolean){
ps.setBoolean(i+1, (Boolean)o);
} else {
ps.setObject(i+1, o);
}
}
}
示例9: getBinder
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setFloat( index, javaTypeDescriptor.unwrap( value, Float.class, options ) );
}
};
}
示例10: setMoney
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static void setMoney(String uuid, float newAmount) {
PlayerUtil.initDataset(uuid);
try {
String query = "UPDATE users SET money = ? WHERE uuid = ?";
PreparedStatement prepStmt = McLink.instance.database.getConnection().prepareStatement(query);
prepStmt.setFloat(1, newAmount);
prepStmt.setString(2, uuid);
prepStmt.executeUpdate();
prepStmt.close();
McLink.instance.database.getConnection().commit();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: setNodeAttr
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private void setNodeAttr(Vertex n, String attr, PreparedStatement st, int index) throws SQLException {
if(attr.compareToIgnoreCase("id") == 0) {
st.setInt(index, n.getId());
} else if(attr.compareToIgnoreCase("label") == 0) {
st.setString(index, n.getLabel());
} else if(attr.compareToIgnoreCase("color") == 0) {
st.setString(index, "" + ((double)n.getFillColor().getRed()/256.d)
+","+((double)n.getFillColor().getGreen()/256.d)
+","+((double)n.getFillColor().getBlue()/256.d));
} else if(attr.compareToIgnoreCase("borderColor") == 0) {
st.setString(index, "" + ((double)n.getBorderColor().getRed()/256.d)
+","+((double)n.getBorderColor().getGreen()/256.d)
+","+((double)n.getBorderColor().getBlue()/256.d));
} else if(attr.compareToIgnoreCase("size") == 0) {
st.setDouble(index, n.getSize());
} else if(attr.compareToIgnoreCase("shape") == 0) {
st.setString(index, n.getShape());
} else if(attr.compareToIgnoreCase("width") == 0) {
st.setInt(index, n.getWidth());
} else if(attr.compareToIgnoreCase("hide") == 0) {
st.setBoolean(index, n.isExcluded() );
} else if(attr.compareToIgnoreCase("var1") == 0) {
st.setString(index, n.getVar1() );
} else if(attr.compareToIgnoreCase("var2") == 0) {
st.setString(index, n.getVar2() );
} else if(attr.compareToIgnoreCase("x") == 0) {
st.setFloat(index, (float) n.getPosition().getX() );
} else if(attr.compareToIgnoreCase("y") == 0) {
st.setFloat(index, (float) n.getPosition().getY() );
} else if(attr.compareToIgnoreCase("fixed") == 0) {
st.setBoolean(index, n.isFixed() );
}
}
示例12: writeFloat
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static void writeFloat(Float val, int paramIdx, int sqlType,
PreparedStatement s) throws SQLException {
if (null == val) {
s.setNull(paramIdx, sqlType);
} else {
s.setFloat(paramIdx, val);
}
}
示例13: editUser
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public boolean editUser(User user) throws SQLException {
PreparedStatement stm = c.prepareStatement(SQLStatements.selectUserById);
stm.setInt(1, user.getId());
ResultSet rs = stm.executeQuery();
if (!rs.next()) { // user does not exist
rs.close();
stm.close();
return false;
}
rs.close();
stm.close();
PreparedStatement stm2 = c.prepareStatement(SQLStatements.updateUserById);
stm2.setString(1, user.getFirstName());
stm2.setString(2, user.getLastName());
stm2.setString(3, user.getPhoneNumber());
stm2.setInt(4, user.getGender());
stm2.setString(5, user.getAddress());
stm2.setString(6, user.getNote());
stm2.setString(7, user.getProfilePicture());
stm2.setInt(8, user.getAreaId());
stm2.setInt(9, user.getCityId());
stm2.setInt(10, user.getId());
stm2.executeUpdate();
if (user.getType() == userType.TSOFEN || user.getType() == userType.ADMIN) {
stm2.close();
return true;
}
if (user.getType() == userType.MENTOR) {
PreparedStatement stm3 = c.prepareStatement(SQLStatements.updateMentorById);
stm3.setString(1, ((Mentor) user).getExperience());
stm3.setString(2, ((Mentor) user).getRole());
stm3.setInt(3, ((Mentor) user).getCompany());
stm3.setString(4, ((Mentor) user).getVolunteering());
stm3.setString(5, ((Mentor) user).getWorkHistory());
stm3.setInt(6, user.getId());
stm3.executeUpdate();
stm3.close();
return true;
}
if (user.getType() == userType.MENTEE) {
PreparedStatement stm4 = c.prepareStatement(SQLStatements.updaterMenteeById);
stm4.setFloat(1, ((Mentee) user).getRemainingSemesters());
stm4.setString(2, ((Mentee) user).getGraduationStatus());
stm4.setInt(3, ((Mentee) user).getAcademiclnstitution());
stm4.setFloat(4, ((Mentee) user).getAverage());
stm4.setString(5, ((Mentee) user).getAcademicDicipline());
stm4.setString(6, ((Mentee) user).getAcademicDicipline2());
stm4.setInt(7, ((Mentee) user).getSignedEULA() ? 1 : 0);
stm4.setString(8, ((Mentee) user).getResume());
stm4.setString(9, ((Mentee) user).getGradeSheet());
stm4.setInt(10, user.getId());
stm4.executeUpdate();
stm4.close();
return true;
}
return false;
}
示例14: insertCheckpointSummary
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void insertCheckpointSummary(
String name,
int numRunning,
int numPassed,
int numFailed,
int minResponseTime,
float avgResponseTime,
int maxResponseTime,
float minTransferRate,
float avgTransferRate,
float maxTransferRate,
String transferRateUnit,
int loadQueueId,
boolean closeConnection ) throws DatabaseAccessException {
final String errMsg = "Unable to insert checkpoint summary '" + name + "' for load queue "
+ loadQueueId;
PreparedStatement perparedStatement = null;
try {
refreshInternalConnection();
perparedStatement = connection.prepareStatement("INSERT INTO tCheckpointsSummary"
+ " (name,numRunning,numPassed,numFailed,minResponseTime,avgResponseTime,maxResponseTime,minTransferRate,avgTransferRate,maxTransferRate,transferRateUnit,loadQueueId) "
+ " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
perparedStatement.setString(1, name);
perparedStatement.setInt(2, numRunning);
perparedStatement.setInt(3, numPassed);
perparedStatement.setInt(4, numFailed);
perparedStatement.setInt(5, minResponseTime);
perparedStatement.setFloat(6, avgResponseTime);
perparedStatement.setInt(7, maxResponseTime);
perparedStatement.setFloat(8, minTransferRate);
perparedStatement.setFloat(9, avgTransferRate);
perparedStatement.setFloat(10, maxTransferRate);
perparedStatement.setString(11, transferRateUnit);
perparedStatement.setInt(12, loadQueueId);
int updatedRecords = perparedStatement.executeUpdate();
if (updatedRecords != 1) {
throw new DatabaseAccessException(errMsg);
}
} catch (SQLException e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, perparedStatement);
} else {
DbUtils.closeStatement(perparedStatement);
}
}
}
示例15: setValue
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private static void setValue(PreparedStatement preStmt,int index,Value value)
{
try
{
if(value.isStringValue())
{
preStmt.setString(index, value.getString_value());
}
else if(value.isIntValue())
{
preStmt.setInt(index, value.getInt_value());
}
else if(value.isDoubleValue())
{
preStmt.setDouble(index, value.getDouble_value());
}
else if(value.isBooleanValue())
{
preStmt.setBoolean(index, value.getBoolean_value());
}
else if(value.isBlobValue())
{
preStmt.setBlob(index, value.getBlob_value());
}
else if(value.isBytesValue())
{
preStmt.setBytes(index, value.getBytes_value());
}
else if(value.isLongValue())
{
preStmt.setLong(index, value.getLong_value());
}
else if(value.isFloatValue())
{
preStmt.setFloat(index, value.getFloat_value());
}
else if(value.isBigdecimalValue())
{
preStmt.setBigDecimal(index, value.getBigdecimal_value());
}
else if(value.isByteValue())
{
preStmt.setByte(index, value.getByte_value());
}
else if(value.isDateValue())
{
preStmt.setDate(index, value.getDate_value());
}
else if(value.isTimeValue())
{
preStmt.setTime(index, value.getTime_value());
}
else
{
preStmt.setObject(index, value.getObject_value());
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
DBCException.logException(DBCException.E_PreparedStatement, e);
}
}