当前位置: 首页>>代码示例>>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;未经允许,请勿转载。