当前位置: 首页>>代码示例>>Java>>正文


Java PreparedStatement.execute方法代码示例

本文整理汇总了Java中java.sql.PreparedStatement.execute方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.execute方法的具体用法?Java PreparedStatement.execute怎么用?Java PreparedStatement.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertNivel

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static void insertNivel(Nivel nivel){
	try {
		Connection conn=ConnectionConfiguration.conectar();
	   	
		String query = " insert into nivel (numero_fila,anho,cod_nivel,nombre,abrev,es_imputable)"
		+ " values (?, ?, ?, ?, ?, ?)";
		
		PreparedStatement insert = conn.prepareStatement(query);
		
		insert.setInt (1, nivel.getNumeroFila());
		insert.setInt (2, nivel.getAnio());
		insert.setInt (3, nivel.getNivel());
		insert.setString (4, nivel.getNombreNivel());
		insert.setString (5, nivel.getAbrevNivel());
		insert.setString (6, nivel.getEsImputable());
							
		insert.execute();
		   
		conn.close();
	} catch (SQLException e) {e.printStackTrace();}
		
}
 
开发者ID:stppy,项目名称:spr,代码行数:23,代码来源:SqlInserts.java

示例2: insertProyectoSnipAutorizado

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static void insertProyectoSnipAutorizado(ProyectoSNIPAutorizado proyectoSnipAutorizado){
	try {
		Connection conn=ConnectionConfiguration.conectar();
	   	
		String query = " insert into proyecto_snip_autorizado (anho, monto, entidad_id, entidad_nivel_id, proyecto_snip_id, organismo_financiador_id, fuente_financiamiento_id )"
		+ " values (?, ?, ?, ?, ?, ?, ?, ?)";
		
		PreparedStatement insert = conn.prepareStatement(query);
		insert.setInt (1, proyectoSnipAutorizado.getAnio());
		insert.setDouble (2, proyectoSnipAutorizado.getMonto());
		insert.setDouble (3, proyectoSnipAutorizado.getEntidad());
		insert.setDouble (4, proyectoSnipAutorizado.getNivel());
		insert.setDouble (5, proyectoSnipAutorizado.getCodigoSnip());
		insert.setInt (6, proyectoSnipAutorizado.getCodOrganismoFinanciador());
		insert.setInt (7, proyectoSnipAutorizado.getCodFuenteFinanciamiento());
		
		insert.execute();
		   
		conn.close();
	} catch (SQLException e) {e.printStackTrace();}
		
}
 
开发者ID:stppy,项目名称:spr,代码行数:23,代码来源:SqlInserts.java

示例3: addSubmission

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public synchronized boolean addSubmission(SubmissionDTO submissionDTO) {
    Connection connection;
    PreparedStatement preparedStatement = null;

    try {
        connection = this.dbConfig.getConnection();
        preparedStatement = connection.prepareStatement("INSERT INTO \"main\".\"submission\" (\"bucket\", \"user\",\"timeout\",\"status\",\"data\") VALUES (?,'',?,?,?)");
        preparedStatement.setString(1, "A");
        preparedStatement.setLong(2, System.currentTimeMillis());
        preparedStatement.setInt(3, 0);
        preparedStatement.setString(4, gson.toJson(submissionDTO));
        preparedStatement.execute();
    }
    catch(SQLException ex) {
        return false;
    }
    finally {
        this.helpers.closeQuietly(preparedStatement);
    }

    return true;
}
 
开发者ID:boyter,项目名称:freemoz,代码行数:23,代码来源:QueueDAO.java

示例4: transferRow

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Method declaration
 *
 *
 * @param type
 * @param r
 * @param p
 *
 * @throws SQLException
 */
private void transferRow(TransferResultSet r, PreparedStatement p,
                         int len,
                         int[] types)
                         throws DataAccessPointException, SQLException {

    for (int i = 1; i <= len; i++) {
        int    t = types[i];
        Object o = r.getObject(i);

        if (o == null) {
            if (p != null) {
                p.setNull(i, t);
            }
        } else {
            o = helper.convertColumnValue(o, i, t);

            p.setObject(i, o);
        }
    }

    if (p != null) {
        p.execute();
    }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:35,代码来源:TransferDb.java

示例5: insertTipoPresupuesto

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static void insertTipoPresupuesto(TipoPresupuesto tipoPresupuesto, String usuarioResponsable){
	try {
		Connection conn=ConnectionConfiguration.conectar();
	   	
		String query = " insert into tipo_presupuesto (id,nombre,abrev,descipcion,anho,numero_fila, usuario_responsable)"
		+ " values (?, ?, ?, ?, ?, ?, ?)";
		
		PreparedStatement insert = conn.prepareStatement(query);
		insert.setInt (1, tipoPresupuesto.getId());
		insert.setString (2, tipoPresupuesto.getNombre());
		insert.setString (3, tipoPresupuesto.getAbrev());
		insert.setString (4, tipoPresupuesto.getDescripcion());
		insert.setInt (5, tipoPresupuesto.getAnho());
		insert.setInt (6, tipoPresupuesto.getNumero_fila());
		insert.setString (7, usuarioResponsable);
					
		insert.execute();
		   
		conn.close();
	} catch (SQLException e) {e.printStackTrace();}
}
 
开发者ID:stppy,项目名称:spr,代码行数:22,代码来源:SqlInserts.java

示例6: deleteWaitListBook

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static boolean deleteWaitListBook(int userId, int book_id){
    PreparedStatement statement;
    String query = String.format("DELETE FROM %s WHERE user_id=? AND book_id=?", waitListTable);

    try {
        statement = MySQL.getInstance().getConnection().prepareStatement(query);
        statement.setInt(1,userId);
        statement.setInt(2,book_id);

        statement.execute();
        return true;

    }catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:hisener,项目名称:bbm487s2017g1,代码行数:18,代码来源:Query.java

示例7: insertUnidadMedida

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static void insertUnidadMedida(UnidadMedida unidadMedida){
	try {
		Connection conn=ConnectionConfiguration.conectar();
	   	
		String query = " insert into unidad_medida (id,nombre,abrev)"
		+ " values (?, ?, ?)";
		
		PreparedStatement insert = conn.prepareStatement(query);
		insert.setInt (1, unidadMedida.getCodigoUnidadMedida());
		insert.setString (2, unidadMedida.getNombre());
		insert.setString (3, unidadMedida.getAbreviacion());
					
		insert.execute();
		   
		conn.close();
	} catch (SQLException e) {e.printStackTrace();}
}
 
开发者ID:stppy,项目名称:spr,代码行数:18,代码来源:SqlInserts.java

示例8: deleteEmployee

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void deleteEmployee( int deptId ) {
	Connection conn=null;
	PreparedStatement pstmt=null;
	
	try {
		conn=DemoUtil.getConnection();
		pstmt=conn.prepareStatement( DELETE_SQL );
		pstmt.setInt( 1, deptId );
		pstmt.execute();
	} catch( SQLException e ) {
		e.printStackTrace();
	} finally {
		DBUtil.close( pstmt, conn );
	}
}
 
开发者ID:yswang0927,项目名称:ralasafe,代码行数:16,代码来源:EmployeeManager.java

示例9: main

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * @param args
 * @throws SQLException
 */
public static void main(String[] args) throws SQLException {
    try {
        Class.forName("org.postgresql.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    Connection pub = DriverManager.getConnection(
            "jdbc:postgresql://127.0.0.1/ramus_public", "postgres",
            "postgres");

    Connection dev = DriverManager.getConnection(
            "jdbc:postgresql://127.0.0.1/ramus_public_dev", "postgres",
            "postgres");

    Statement st = dev.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM ramus_cattle_tasks");
    PreparedStatement ps = pub.prepareStatement("UPDATE ramus_cattle_tasks SET name=? WHERE task_id=?");
    int i = 0;
    while (rs.next()) {
        ps.setString(1, rs.getString("name"));
        ps.setLong(2, rs.getLong("task_id"));
        ps.execute();
        i++;
        if (i % 1000 == 0)
            System.out.println(i);
    }
    rs.close();
    st.close();
    ps.close();
    pub.commit();

}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:38,代码来源:FuckRestore.java

示例10: deleteTeam

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void deleteTeam(int id) throws SQLException {
	Connection connect = connectToMySQL();
	
	String queryth = "DELETE FROM `team_hero` WHERE team_id=?";
	PreparedStatement stath = connect.prepareStatement(queryth, Statement.RETURN_GENERATED_KEYS);
	stath.setInt(1, id);
	stath.execute();
	
	String query = "DELETE FROM `team` WHERE team_id=?";
	PreparedStatement stateam = connect.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
	stateam.setInt(1, id);
	stateam.execute();
	connect.close();
}
 
开发者ID:Bartac,项目名称:avengers-db,代码行数:15,代码来源:TeamDAO.java

示例11: testSetNCharacterStreamServer

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Tests for ServerPreparedStatement.setNCharacterSteam()
 * 
 * @throws Exception
 */
public void testSetNCharacterStreamServer() throws Exception {
    createTable("testSetNCharacterStreamServer", "(c1 NATIONAL CHARACTER(10)) ENGINE=InnoDB");
    Properties props1 = new Properties();
    props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
    props1.put("useUnicode", "true");
    props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
    Connection conn1 = getConnectionWithProps(props1);
    PreparedStatement pstmt1 = conn1.prepareStatement("INSERT INTO testSetNCharacterStreamServer (c1) VALUES (?)");
    try {
        pstmt1.setNCharacterStream(1, new StringReader("aaa"), 3);
        fail();
    } catch (SQLException e) {
        // ok
        assertEquals("Can not call setNCharacterStream() when connection character set isn't UTF-8", e.getMessage());
    }
    pstmt1.close();
    conn1.close();

    createTable("testSetNCharacterStreamServer", "(c1 LONGTEXT charset utf8) ENGINE=InnoDB");
    Properties props2 = new Properties();
    props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
    props2.put("useUnicode", "true");
    props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
    Connection conn2 = getConnectionWithProps(props2);
    PreparedStatement pstmt2 = conn2.prepareStatement("INSERT INTO testSetNCharacterStreamServer (c1) VALUES (?)");
    pstmt2.setNCharacterStream(1, new StringReader(new String(new char[81921])), 81921); // 10 Full Long Data Packet's chars + 1 char
    pstmt2.execute();
    ResultSet rs2 = this.stmt.executeQuery("SELECT c1 FROM testSetNCharacterStreamServer");
    rs2.next();
    assertEquals(new String(new char[81921]), rs2.getString(1));
    rs2.close();
    pstmt2.close();
    conn2.close();
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:40,代码来源:StatementsTest.java

示例12: start

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void start(long startTime, int leaderAddress) throws SQLException {
    Timestamp timestamp = new Timestamp(startTime);
    if (LOG.isDebugEnabled())
        LOG.debug(String.format("Cluster Start Time: %s [%d]", timestamp, startTime));
    
    PreparedStatement instanceStmt =
        m_conn.prepareStatement(
                createInstanceStatement,
                PreparedStatement.RETURN_GENERATED_KEYS);
    insertConnectionStatsStmt = m_conn.prepareStatement(insertConnectionStatsStatement);
    insertProcedureStatsStmt = m_conn.prepareStatement(insertProcedureStatsStatement);
    instanceStmt.setTimestamp( 1, timestamp);
    instanceStmt.setInt( 2, leaderAddress);
    instanceStmt.setString( 3, m_applicationName);
    if (m_subApplicationName != null) {
        instanceStmt.setString( 4, m_subApplicationName);
    } else {
        instanceStmt.setNull( 4, Types.VARCHAR);
    }
    instanceStmt.setInt(5, CatalogUtil.getNumberOfHosts(m_settings.getCatalog()));
    instanceStmt.setInt(6, CatalogUtil.getNumberOfSites(m_settings.getCatalog()));
    instanceStmt.setInt(7, CatalogUtil.getNumberOfPartitions(m_settings.getCatalog()));
    instanceStmt.execute();
    ResultSet results = instanceStmt.getGeneratedKeys();
    while (results.next()) {
        m_instanceId = results.getInt( 1 );
    }
    results.close();
    instanceStmt.close();
    if (m_instanceId < 0) {
        throw new SQLException("Unable to generate an instance id to identify this client");
    }
    insertConnectionStatsStmt.setInt( 1, m_instanceId);
    insertProcedureStatsStmt.setInt( 1, m_instanceId);
    m_conn.commit();
    m_loadThread.setDaemon(true);
    m_loadThread.start();
    if (LOG.isDebugEnabled())
        LOG.debug("ClientStatsLoader has been started");
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:41,代码来源:ClientStatsSqlLoader.java

示例13: jButton2ActionPerformed

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    try {
        Random rm = new Random();
        Ejercicio ejNuevo = new Ejercicio();
        
        ejNuevo.codEj = rm.nextInt(50000);
        ejNuevo.expresion= jTextField1.getText();
        ejNuevo.resultado = parseInt(jTextField2.getText());
        ejNuevo.nivelEj.numeroNivel=parseInt((String) jComboBox1.getSelectedItem());
        ejNuevo.puntaje= parseInt(jTextField3.getText()) ;
        
        ConectarBD con = new ConectarBD();
        Connection cn=null;
        cn = con.getCon();
        
        String sql = " INSERT INTO ejercicio (codEj, expresion, resultado, numNivel, puntaje)"
    + " values (?, ?, ?, ?, ?)";
        
        PreparedStatement st = cn.prepareStatement(sql);
       
        
         st.setInt(1, ejNuevo.codEj);
         st.setString(2, ejNuevo.expresion);
         st.setInt(3, ejNuevo.resultado);
         st.setInt(4, ejNuevo.nivelEj.numeroNivel);
         st.setInt(5, ejNuevo.puntaje);
        
        
         st.execute();
    } catch (SQLException ex) {
        Logger.getLogger(CrearEjercicio.class.getName()).log(Level.SEVERE, null, ex);
         JOptionPane.showMessageDialog(null, "No se ha podido Guardar.");
    }
    
    JOptionPane.showMessageDialog(null, "Se ha guardado correctamente.");
    this.setVisible(false);
    
}
 
开发者ID:maticorv,项目名称:ProyectoTestUnitario,代码行数:39,代码来源:CrearEjercicio.java

示例14: 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");
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:38,代码来源:TestCacheSize.java

示例15: set

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void set(String type, String value) {
    createDefaultEntryIfNotExist();
    try {
        if (connection.isClosed())
            mySQL.connect();
        PreparedStatement ps = connection.prepareStatement("UPDATE music_users SET " + type + "=? WHERE userid=?");
        ps.setString(1, value);
        ps.setString(2, user.getId());
        ps.execute();
    } catch (SQLException e) {
        Logger.error(e);
    }
}
 
开发者ID:Rubicon-Bot,项目名称:Rubicon,代码行数:14,代码来源:UserMusicSQL.java


注:本文中的java.sql.PreparedStatement.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。