本文整理匯總了Java中java.sql.PreparedStatement.setShort方法的典型用法代碼示例。如果您正苦於以下問題:Java PreparedStatement.setShort方法的具體用法?Java PreparedStatement.setShort怎麽用?Java PreparedStatement.setShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.setShort方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insert
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private int insert(Connection con,List<Map<String, String>> list) throws SQLException {
PreparedStatement ps;
String sql = "insert into goods (id,name ,good_type,good_img_url,good_created ,good_desc, price ) values(?,? ,?,?,? ,?, ?)";
ps = con.prepareStatement(sql);
for (Map<String, String> map : list) {
ps.setLong(1, Long.parseLong(map.get("id")));
ps.setString(2, (String) map.get("name"));
ps.setShort(3, Short.parseShort(map.get("good_type")));
ps.setString(4, (String) map.get("good_img_url"));
ps.setString(5, (String) map.get("good_created"));
ps.setString(6, (String) map.get("good_desc"));
ps.setDouble(7, Double.parseDouble(map.get("price")));
ps.addBatch();
}
ps.executeBatch();
return list.size();
}
示例2: 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;
}
示例3: insert
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private int insert(Connection con, List<Map<String, String>> list) throws SQLException {
PreparedStatement ps;
String sql = "insert into goods (id,name ,good_type,good_img_url,good_created ,good_desc, price ) values(?,? ,?,?,? ,?, ?)";
ps = con.prepareStatement(sql);
for (Map<String, String> map : list) {
ps.setLong(1, Long.parseLong(map.get("id")));
ps.setString(2, (String) map.get("name"));
ps.setShort(3, Short.parseShort(map.get("good_type")));
ps.setString(4, (String) map.get("good_img_url"));
ps.setString(5, (String) map.get("good_created"));
ps.setString(6, (String) map.get("good_desc"));
ps.setDouble(7, Double.parseDouble(map.get("price")));
ps.addBatch();
}
ps.executeBatch();
return list.size();
}
示例4: 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.setShort( index, javaTypeDescriptor.unwrap( value, Short.class, options ) );
}
};
}
示例5: testSmallIntComplex
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void testSmallIntComplex() {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = netConn.prepareStatement(
"INSERT INTO alltypes(id, si) VALUES(?, ?)");
ps.setInt(1, 3);
ps.setShort(2, (short) 395);
assertEquals(1, ps.executeUpdate());
ps.setInt(1, 4);
assertEquals(1, ps.executeUpdate());
ps.close();
netConn.commit();
ps = netConn.prepareStatement(
"SELECT * FROM alltypes WHERE si = ?");
ps.setShort(1, (short) 395);
rs = ps.executeQuery();
assertTrue("Got no rows with si = 395", rs.next());
assertEquals(Integer.class, rs.getObject("si").getClass());
// Nb. HyperSQL purposefully returns an Integer for this type
assertTrue("Got only one row with si = 395", rs.next());
assertEquals((short) 395, rs.getShort("si"));
assertFalse("Got too many rows with si = 395", rs.next());
} catch (SQLException se) {
junit.framework.AssertionFailedError ase
= new junit.framework.AssertionFailedError(se.getMessage());
ase.initCause(se);
throw ase;
} finally {
try {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
} catch(Exception e) {
}
}
}
示例6: payment
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/**
* Payment by customer last name. Section 2.5.2 The CUSTOMER row will be
* fetched and then updated. This is due to the need to select the specific
* customer first based upon last name (which will actually fetch and hence
* lock a number of customers).
*/
public void payment(Display display, Object displayData, short w, short d, short cw, short cd, String customerLast, String amount) throws Exception {
PreparedStatement pyCustomerByName = prepareStatement("SELECT C_ID " + "FROM CUSTOMER WHERE C_W_ID = ? AND C_D_ID = ? AND C_LAST = ? " + "ORDER BY C_FIRST");
// Since so much data is needed for the payment transaction
// from the customer we don't fill it in as we select the
// correct customer. Instead we just fetch the identifier
// and then execute a payment by identifier.
try {
pyCustomerByName.setShort(1, cw);
pyCustomerByName.setShort(2, cd);
pyCustomerByName.setString(3, customerLast);
ResultSet rs = pyCustomerByName.executeQuery();
nameList.clear();
while (rs.next()) {
nameList.add(rs.getObject("C_ID"));
}
reset(pyCustomerByName);
if (nameList.isEmpty())
throw new SQLException("Payment by name - no matching customer " + customerLast);
// Customer to use is midpoint (with round up) (see 2.5.2.2)
int mid = nameList.size() / 2;
if (mid != 0) {
if (nameList.size() % 2 == 1)
mid++;
}
int c = ((Integer) nameList.get(mid)).intValue();
paymentById(display, displayData, w, d, cw, cd, c, amount);
} catch (SQLException e) {
conn.rollback();
throw e;
}
if (display != null)
;
}
示例7: setNonNullParameter
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Short parameter, JdbcType jdbcType) throws SQLException {
ps.setShort(i, parameter);
}
示例8: setValue
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
protected void setValue(PreparedStatement ps, int i, Short value)
throws SQLException {
ps.setShort(i, value);
}
示例9: applyParameterMapToPreparedStatement
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private PreparedStatement applyParameterMapToPreparedStatement(
PreparedStatement preparedStatement,
Map<String, Object> parameterMap,
List<String> parametersInSqlSorted) {
try {
for (int i = 0; i < parametersInSqlSorted.size(); i++) {
Object value = parameterMap.get(parametersInSqlSorted.get(i));
int positionInPreparedStatement = i + 1; // jdbc parameters start with 1...
if (value instanceof BigDecimal) {
preparedStatement.setBigDecimal(positionInPreparedStatement, (BigDecimal) value);
} else if (value instanceof Boolean) {
preparedStatement.setBoolean(positionInPreparedStatement, (Boolean) value);
} else if (value instanceof Date) {
preparedStatement.setDate(positionInPreparedStatement, (Date) value);
} else if (value instanceof Double) {
preparedStatement.setDouble(positionInPreparedStatement, (Double) value);
} else if (value instanceof Float) {
preparedStatement.setFloat(positionInPreparedStatement, (Float) value);
} else if (value instanceof Integer) {
preparedStatement.setInt(positionInPreparedStatement, (Integer) value);
} else if (value instanceof Long) {
preparedStatement.setLong(positionInPreparedStatement, (Long) value);
} else if (value instanceof Short) {
preparedStatement.setShort(positionInPreparedStatement, (Short) value);
} else if (value instanceof String) {
preparedStatement.setString(positionInPreparedStatement, (String) value);
} else if (value instanceof Time) {
preparedStatement.setTime(positionInPreparedStatement, (Time) value);
} else if (value instanceof Timestamp) {
preparedStatement.setTimestamp(positionInPreparedStatement, (Timestamp) value);
} else if (value instanceof URL) {
preparedStatement.setURL(positionInPreparedStatement, (URL) value);
} else {
// Kind of a fallback. If you expect some other behavior feel
// free to implement it.
preparedStatement.setObject(positionInPreparedStatement, value);
}
}
} catch (SQLException ex) {
throw new SqlifyException("Ops. An error occurred.", ex);
}
return preparedStatement;
}
示例10: saveToDB
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void saveToDB() {
Connection con = DatabaseConnection.getConnection();
try {
if (getNPCFromWZ() == null) {
destroy(true);
return;
}
destroy();
PreparedStatement ps = con.prepareStatement("INSERT INTO playernpcs(name, hair, face, skin, x, y, map, charid, scriptid, foothold, dir, gender, pets, job, elf, faceMarking) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
int k = 0;
ps.setString(++k, getName());
ps.setInt(++k, getHair());
ps.setInt(++k, getFace());
ps.setInt(++k, getSkinColor());
ps.setInt(++k, getTruePosition().x);
ps.setInt(++k, getTruePosition().y);
ps.setInt(++k, getMapId());
ps.setInt(++k, getCharId());
ps.setInt(++k, getId());
ps.setInt(++k, getFh());
ps.setInt(++k, getF());
ps.setInt(++k, getGender());
String[] pet = {"0", "0", "0"};
for (int i = 0; i < 3; i++) {
if (pets[i] > 0) {
pet[i] = String.valueOf(pets[i]);
}
}
ps.setString(++k, pet[0] + "," + pet[1] + "," + pet[2]);
ps.setShort(++k, getJob());
ps.setInt(++k, getElf());
ps.setInt(++k, getFaceMarking());
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("INSERT INTO playernpcs_equip(npcid, charid, equipid, equippos) VALUES (?, ?, ?, ?)");
ps.setInt(1, getId());
ps.setInt(2, getCharId());
for (Entry<Byte, Integer> equip : equips.entrySet()) {
ps.setInt(3, equip.getValue());
ps.setInt(4, equip.getKey());
ps.executeUpdate();
}
ps.close();
} catch (SQLException se) {
}
}
示例11: setParameter
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void setParameter(PreparedStatement ps, int i, Object parameter) throws SQLException {
ps.setShort(i, ((Short) parameter).shortValue());
}