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


Java PreparedStatement.setShort方法代碼示例

本文整理匯總了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();
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:18,代碼來源:GoodsInsertJob.java

示例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;
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:32,代碼來源:SQL.java

示例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();
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:18,代碼來源:GoodsInsertJob.java

示例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 ) );
		}
	};
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:SmallIntTypeDescriptor.java

示例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) {
        }
    }
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:41,代碼來源:TestOdbcTypes.java

示例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)
    ;
}
 
開發者ID:RuiChen08,項目名稱:dacapobench,代碼行數:47,代碼來源:Operation.java

示例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);
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:5,代碼來源:ShortTypeHandler.java

示例8: setValue

import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
protected void setValue(PreparedStatement ps, int i, Short value)
        throws SQLException {
    ps.setShort(i, value);
}
 
開發者ID:tiglabs,項目名稱:jsf-core,代碼行數:6,代碼來源:ConvertableEnumTypeHandler.java

示例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;
}
 
開發者ID:r10r-org,項目名稱:sqlify,代碼行數:45,代碼來源:Sqlify.java

示例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) {
    }
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:49,代碼來源:PlayerNPC.java

示例11: setParameter

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void setParameter(PreparedStatement ps, int i, Object parameter) throws SQLException {

            ps.setShort(i, ((Short) parameter).shortValue());
        }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:5,代碼來源:DAOFactory.java


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