本文整理匯總了Java中java.sql.PreparedStatement.setInt方法的典型用法代碼示例。如果您正苦於以下問題:Java PreparedStatement.setInt方法的具體用法?Java PreparedStatement.setInt怎麽用?Java PreparedStatement.setInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.setInt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setFullPullReqTblSqlParam
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private void setFullPullReqTblSqlParam(PreparedStatement pStmt, String startTime, String completedTime,
String pullStatus, String errorMsg, int seqno) throws SQLException {
int paraIndex = 1;
if(pStmt != null){
if(StringUtils.isNotEmpty(startTime)){
pStmt.setString(paraIndex, startTime);
paraIndex++;
}
if (StringUtils.isNotEmpty(completedTime)){
pStmt.setString(paraIndex, completedTime);
paraIndex++;
}
if (StringUtils.isNotEmpty(pullStatus)) {
pStmt.setString(paraIndex, pullStatus);
paraIndex++;
}
if (StringUtils.isNotEmpty(errorMsg)) {
errorMsg = errorMsg.length()>1000?errorMsg.substring(0,1000):errorMsg;
pStmt.setString(paraIndex, errorMsg);
paraIndex++;
}
pStmt.setInt(paraIndex, seqno);
}
}
示例2: populateContestants
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private void populateContestants() {
String q = "insert into contestants values(?, ?)";
for (int i = 0; i < TABLE_SIZE; i++) {
try {
PreparedStatement sel = conn.prepareStatement(q);
sel.setInt(1, i);
sel.setString(2, "constants" + i);
sel.execute();
int count = sel.getUpdateCount();
assertTrue(count==1);
}
catch(SQLException e) {
System.err.printf("ERROR(INSERT): %s value='%s': %s\n",
"votes", i, e.getMessage());
fail();
}
}
}
示例3: insertAvanceCualitativo
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static boolean insertAvanceCualitativo(AvanceCualitativo avanceCualitativo, String usuarioResponsable)throws ParseException{
try {
Connection conn=ConnectionConfiguration.conectar();
String query = " insert into avance_cualitativo (accion_catalogo_id, ins_linea_accion_id, trimestre_id, gestiones_realizadas, principales_logros_alcanzados, dificultades_lecciones_aprendidas, objetivos_del_siguiente_trimestre, usuario_responsable)"
+ " values (?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement insert = conn.prepareStatement(query);
insert.setInt (1, avanceCualitativo.getAccionCatalogoId());
insert.setInt (2, avanceCualitativo.getInsLineaAccionId());
insert.setInt (3, avanceCualitativo.getTrimestreId());
insert.setString (4, avanceCualitativo.getGestionesRealizadas());
insert.setString (5, avanceCualitativo.getPrincipalesLogrosAlcanzados());
insert.setString (6, avanceCualitativo.getDificultadesLeccionesAprendidas());
insert.setString (7, avanceCualitativo.getObjetivosTrimestre());
insert.setString (8, usuarioResponsable);
insert.execute();
conn.close();
return true;
} catch (SQLException e) {e.printStackTrace(); return false;}
}
示例4: insertTpoPrograma
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static void insertTpoPrograma(int codTipoPrograma, int numero_fila, int anio, String nombreTipoPrograma, String abrev){
Connection conect=conectar();
String query = " insert into tipo_presupuesto (id, numero_fila, anho, nombre, descipcion, abrev)"
+ " values (?,?,?,?,?,?)";
try {
PreparedStatement preparedStmt;
preparedStmt = conect.prepareStatement(query);
preparedStmt.setInt (1, codTipoPrograma);
preparedStmt.setInt (2, numero_fila);
preparedStmt.setInt (3, anio);
preparedStmt.setString (4, nombreTipoPrograma);
preparedStmt.setString (5, "");
preparedStmt.setString (6, abrev);
preparedStmt.execute();
conect.close();
} catch (SQLException e) {e.printStackTrace();}
}
示例5: setArgs
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/**
* 設置參數
*
* @param pstmt
* @param dimension
* @throws SQLException
*/
private void setArgs(PreparedStatement pstmt, BaseDimension dimension) throws SQLException {
int i = 0;
if (dimension instanceof DateDimension) {
DateDimension date = (DateDimension) dimension;
pstmt.setInt(++i, date.getYear());
pstmt.setInt(++i, date.getSeason());
pstmt.setInt(++i, date.getMonth());
pstmt.setInt(++i, date.getWeek());
pstmt.setInt(++i, date.getDay());
pstmt.setString(++i, date.getType());
pstmt.setDate(++i, new Date(date.getCalendar().getTime()));
} else if (dimension instanceof PlatformDimension) {
PlatformDimension platform = (PlatformDimension) dimension;
pstmt.setString(++i, platform.getPlatformName());
} else if (dimension instanceof BrowserDimension) {
BrowserDimension browser = (BrowserDimension) dimension;
pstmt.setString(++i, browser.getBrowserName());
pstmt.setString(++i, browser.getBrowserVersion());
}
}
示例6: execUpdate
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void execUpdate(Map<Integer, String> idToName) {
try {
getConnection().setAutoCommit(false);
String update = "insert into users(id, user_name) values(?,?)";
PreparedStatement stmt = getConnection().prepareStatement(update);
for (Integer id : idToName.keySet()) {
stmt.setInt(1, id);
stmt.setString(2, idToName.get(id));
stmt.executeUpdate();
}
getConnection().commit();
stmt.close();
} catch (SQLException e) {
try {
getConnection().rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
}
示例7: remover
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/**
* Método para remover perguntas do Banco de Dados
*/
@Autor("Divino Matheus")
public ModelPergunta remover(ModelPergunta modelPergunta) {
abrirConexao();
try {
String sql = "DELETE FROM perguntas WHERE id=?";
PreparedStatement stmt = this.conexao.prepareStatement(sql);
stmt.setInt(1, modelPergunta.getId());
stmt.executeUpdate();
stmt.close();
JOptionPane.showMessageDialog(null, "Pergunta removida com sucesso!", "Processo concluído!", -1);
} catch (Exception e) {
e.getMessage();
} finally {
fecharConexao();
}
return null;
}
示例8: setVersionInformation
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/**
* Sets the specified version information in the version table in the
* database.
*
* @param conn
* The database connection.
* @param versionInfoToSet
* The version information to be set.
* @throws SQLException
*/
private void setVersionInformation(Connection conn,
DatabaseVersionInfo versionInfoToSet, long time)
throws SQLException {
Statement stmt = conn.createStatement();
try {
stmt.execute("DELETE FROM VERSION");
} finally {
closeStatement(stmt);
}
PreparedStatement pStmt = conn
.prepareStatement("INSERT INTO VERSION(productMajorVersion, productMinorVersion, schemaVersion, migrationDate) VALUES(?,?,?,?)");
try {
pStmt.setInt(1, versionInfoToSet.getProductMajorVersion());
pStmt.setInt(2, versionInfoToSet.getProductMinorVersion());
pStmt.setInt(3, versionInfoToSet.getSchemaVersion());
pStmt.setTimestamp(4, new Timestamp(time));
pStmt.execute();
} finally {
closeStatement(pStmt);
}
}
示例9: getWaitListBook
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static boolean getWaitListBook(int user_id, int book_id){
PreparedStatement statement;
String query = String.format("SELECT * FROM %s WHERE user_id=? AND book_id=?", waitListTable);
try {
statement = MySQL.getInstance().getConnection().prepareStatement(query);
statement.setInt(1,user_id);
statement.setInt(2,book_id);
ResultSet resultSet= statement.executeQuery();
// check isEmpty
if (!resultSet.next()) {
return false;
}
return true;
}catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例10: createHero
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public int createHero(String name, String realname) throws SQLException{
String query = "INSERT INTO `heroes` (`name`, `sex`, `likes`, `dislikes`, `picture`, `abilities`, `history`) VALUES (?, '', '0', '0', NULL, NULL, NULL)";
Connection connect = connectToMySQL();
PreparedStatement statement = connect.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
statement.setString(1, name);
statement.execute();
ResultSet rs = statement.getGeneratedKeys();
int id = -1;
if(rs.next()){
id = rs.getInt(1);
}
System.out.println("id " + id);
String queryirl = "INSERT INTO `irl` (`hero_id`, `name`) VALUES (?,?)";
PreparedStatement statementirl = connect.prepareStatement(queryirl, Statement.RETURN_GENERATED_KEYS);
statementirl.setInt(1, id);
statementirl.setString(2, realname);
statementirl.execute();
connect.close();
return id;
}
示例11: countOfferedMessages
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
public int countOfferedMessages(Connection txn, ContactId c)
throws DbException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = "SELECT COUNT (messageId) FROM offers "
+ " WHERE contactId = ?";
ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt());
rs = ps.executeQuery();
if (!rs.next()) throw new DbException();
int count = rs.getInt(1);
if (rs.next()) throw new DbException();
rs.close();
ps.close();
return count;
} catch (SQLException e) {
tryToClose(rs);
tryToClose(ps);
throw new DbException(e);
}
}
示例12: selectZip
import java.sql.PreparedStatement; //導入方法依賴的package包/類
void selectZip() {
StopWatch sw = new StopWatch();
java.util.Random randomgen = new java.util.Random();
int i = 0;
boolean slow = false;
try {
PreparedStatement ps = cConnection.prepareStatement(
"SELECT TOP 1 firstname,lastname,zip,filler FROM test WHERE zip = ?");
for (; i < bigops; i++) {
ps.setInt(1, nextIntRandom(randomgen, smallrows));
ps.execute();
if ((i + 1) == 100 && sw.elapsedTime() > 50000) {
slow = true;
}
if (reportProgress && (i + 1) % 10000 == 0
|| (slow && (i + 1) % 100 == 0)) {
System.out.println("Select " + (i + 1) + " : "
+ sw.elapsedTime() + " rps: "
+ (i * 1000 / (sw.elapsedTime() + 1)));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
long time = sw.elapsedTime();
long rate = ((long) i * 1000) / (time + 1);
storeResult("select random zip", i, time, rate);
System.out.println("select time for random zip " + i + " rows -- "
+ time + " ms -- " + rate + " tps");
}
示例13: testBug74932ExecuteStmts
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private void testBug74932ExecuteStmts(final Connection testConn, final String sqlOuter, final String sqlInner) throws SQLException {
PreparedStatement psOuter = null;
PreparedStatement psInner = null;
ResultSet rsOuter = null;
ResultSet rsInner = null;
psOuter = testConn.prepareStatement(sqlOuter);
psOuter.setInt(1, 1);
rsOuter = psOuter.executeQuery();
for (int i = 0; i < 2; i++) {
assertTrue(rsOuter.next());
try {
psInner = testConn.prepareStatement(sqlInner);
psInner.setInt(1, 2);
rsInner = psInner.executeQuery();
assertTrue(rsInner.next());
assertTrue(rsInner.next());
assertFalse(rsInner.next());
} finally {
if (rsInner != null) {
rsInner.close();
}
psInner.close();
}
}
assertFalse(rsOuter.next());
rsOuter.close();
rsInner.close();
psOuter.close();
}
示例14: updateProduto
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public Produto updateProduto(Produto produto) throws Exception{
System.out.println("Atualizando produto...");
String query = "UPDATE produtos SET codigoempresa=?, nome=?, descricao=?, codigofornecedor=?, codigocategoria=?, precocompra=?, precovenda=?, estoque=? WHERE codigo=?";
try {
PreparedStatement preparedStatement = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setInt(1, produto.getCodigoempresa());
preparedStatement.setString(2, produto.getNome());
preparedStatement.setString(3, produto.getDescricao());
preparedStatement.setInt(4, produto.getCodigoFornecedor());
preparedStatement.setInt(5, produto.getCategoria());
preparedStatement.setDouble(6, produto.getPrecocompra());
preparedStatement.setDouble(7, produto.getPrecovenda());
preparedStatement.setInt(8, produto.getEstoque());
preparedStatement.setInt(9, produto.getCodigo());
preparedStatement.executeUpdate();
preparedStatement.close();
} catch (SQLException ex) {
System.out.println("Erro ao atualizar produto");
throw new Exception("Erro ao atualizar produto", ex);
}
return produto;
}
示例15: inserir
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/**
* Método responsável pela inserção de um objeto no banco de dados na tabela usuários
* @param dto objeto com os dados de usuário já preenchido
* @throws Exception
*/
@Override
public void inserir(Usuario dto) throws Exception {
Connection conexao = getConexao();
PreparedStatement pstmt = conexao.prepareStatement("insert into usuarios(nome, email, telefone, senha, data_nascimento, sexo, data_cadastro, status, foto, cidade) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
pstmt.setString(1, dto.getNome());
pstmt.setString(2, dto.getEmail());
pstmt.setString(3, dto.getTelefone());
pstmt.setString(4, dto.getSenha());
pstmt.setDate(5, new java.sql.Date(dto.getDataNascimento().getTime()));
pstmt.setString(6, String.valueOf(dto.getSexo().getId()));
pstmt.setDate(7, new java.sql.Date(dto.getDataCadastro().getTime()));
pstmt.setBoolean(8, dto.getStatus());
if (dto.getFoto() != null){
pstmt.setInt(9, dto.getFoto().getId());
} else {
pstmt.setNull(9, Types.BLOB);
}
pstmt.setInt(10, dto.getCidade().getId());
/**
* executa uma inserção
*/
pstmt.executeUpdate();
dto.setId(getId(pstmt));
}