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


Java Connection.createStatement方法代码示例

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


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

示例1: mbushTabelen

import java.sql.Connection; //导入方法依赖的package包/类
public void mbushTabelen(){
    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                Connection conn = DriverManager.getConnection(CON_STR, "test", "test");
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery("select * from Konsumatori");
                ObservableList<TabelaKonsumatori> data = FXCollections.observableArrayList();
                while (rs.next()){
                    data.add(new TabelaKonsumatori(rs.getInt("id"), rs.getString("emri"), rs.getString("mbiemri"),
                            rs.getString("makina"), rs.getString("komuna"), rs.getString("pershkrimi")));
                }
                table.setItems(data);
                conn.close();
            }catch (Exception ex){ex.printStackTrace();}
        }
    });
    t.start();
}
 
开发者ID:urankajtazaj,项目名称:Automekanik,代码行数:20,代码来源:ShikoKonsumatoret.java

示例2: dropTable

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Drop a table if it exists.
 */
public static void dropTable(String tableName, ConnManager manager)
    throws SQLException {
  Connection connection = null;
  Statement st = null;

  try {
    connection = manager.getConnection();
    connection.setAutoCommit(false);
    st = connection.createStatement();

    // create the database table and populate it with data.
    st.executeUpdate(getDropTableStatement(tableName));

    connection.commit();
  } finally {
    try {
      if (null != st) {
        st.close();
      }
    } catch (SQLException sqlE) {
      LOG.warn("Got SQLException when closing connection: " + sqlE);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:28,代码来源:OracleUtils.java

示例3: getList

import java.sql.Connection; //导入方法依赖的package包/类
public ObservableList<Sale> getList(String sqlQuery, ObservableList<Sale> saleListDetails) {
    String date, patientName, doctorName, companyName, mode;
    Long billNumber;
    Float amount;
    try {
        Connection dbConnection = JDBC.databaseConnect();
        Statement sqlStatement = dbConnection.createStatement();
        ResultSet saleResultSet = sqlStatement.executeQuery(sqlQuery);
        while (saleResultSet.next()) {
            date = saleResultSet.getString("date");
            patientName = saleResultSet.getString("patient_name");
            companyName = saleResultSet.getString("company");
            doctorName = saleResultSet.getString("doctor_name");
            mode = saleResultSet.getString("mode");
            billNumber = saleResultSet.getLong("bill_no");
            amount = saleResultSet.getFloat("total_amount");
            saleListDetails.add(new Sale(date, billNumber, patientName, doctorName, companyName, mode, amount));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return saleListDetails;
}
 
开发者ID:alchemsynergy,项目名称:alchem,代码行数:24,代码来源:ViewSaleController.java

示例4: updateUnidadMedida

import java.sql.Connection; //导入方法依赖的package包/类
public static void updateUnidadMedida(String id, String nombre,
		String abrev, String simbolo, String descripcion) {
	Connection conect = ConnectionConfiguration.conectar();
	Statement statement = null;
	String query = "update unidad_medida set ";
	// if (id!="") query+= "id=\""+id+"\", ";
	if (nombre != "")
		query += "nombre=\"" + nombre + "\", ";
	if (abrev != "")
		query += "abrev=\"" + abrev + "\", ";
	if (simbolo != "")
		query += "simbolo=\"" + simbolo + "\", ";
	if (descripcion != "")
		query += "descripcion=\"" + descripcion + "\", ";
	query = query.substring(0, query.length() - 2);
	query += "where id=" + id;

	try {
		statement = conect.createStatement();
		statement.execute(query);
		conect.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
开发者ID:stppy,项目名称:spr,代码行数:26,代码来源:SqlUpdates.java

示例5: findTeamById

import java.sql.Connection; //导入方法依赖的package包/类
public Team findTeamById(String term) throws SQLException {

		String query = "SELECT t.team_id, t.team_name, t.history, t.picture AS team_picture, h.name AS hero_name, h.picture AS hero_picture "
				+ "FROM team t LEFT JOIN team_hero th ON t.team_id = th.team_id "
				+ "LEFT JOIN heroes h ON th.hero_id = h.id " + "WHERE t.team_id='"+ term + "'";

		Connection connect = connectToMySQL();
		Statement statement = connect.createStatement();
		ResultSet resultSet = statement.executeQuery(query);
		if (resultSet.next()) {
			Team team = resultSetToTeam(resultSet);
			connect.close();
			return team;
		} else {
			connect.close();
			return null;
		}
	}
 
开发者ID:Bartac,项目名称:avengers-db,代码行数:19,代码来源:TeamDAO.java

示例6: upgrade

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Perform upgrade.
 */
public void upgrade(final Connection conn, final int upgradeToVersion) throws SQLException {
  final boolean savedAutoCommit = conn.getAutoCommit();
  Statement st = null; // NOPMD
  try {
    // create statement
    conn.setAutoCommit(true);
    st = conn.createStatement();

    LOG.debug("Altering table");
    PersistanceUtils.executeDDLs(st, new String[]{
            " alter table TEST_CASE drop constraint TEST_CASE_UC2",
            " alter table TEST_CASE add constraint TEST_CASE_UC2 unique (TEST_PACKAGE_ID, NAME)",
    });

    LOG.debug("Updating version");
    st.executeUpdate("update SYSTEM_PROPERTY set VALUE = '" + upgraderVersion() + "' where NAME = 'parabuild.schema.version' ");

    // finish
    conn.commit();

  } finally {
    IoUtils.closeHard(st);
    conn.setAutoCommit(savedAutoCommit);
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:UpgraderToVersion65.java

示例7: query

import java.sql.Connection; //导入方法依赖的package包/类
public boolean query(String sql) {
    try {
        Statement stmt = getStatement();
        if (stmt != null) {
            stmt.close();
        }
        ResultSet rs = getResultSet();
        if (rs != null) {
            rs.close();
        }
        Connection con = getConnection();
        if (con == null) {
            return false;
        }
        stmt = con.createStatement();
        setStatement(stmt);
        setResultSet(stmt.executeQuery(sql));
        return true;
    } catch (Exception e) {
        Debug.warning(e);
        return false;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:Database.java

示例8: initStartCount

import java.sql.Connection; //导入方法依赖的package包/类
private void initStartCount(Connection conn) {
    try {
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt
                .executeQuery("SELECT MAX(TKEY) FROM " + TABLE_NAME);
        while (rs.next()) {
            count = rs.getInt(1);
        }
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException(
                "Could not determine max id value in use.");
    }

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:PropertyImport.java

示例9: borradoSprProducto

import java.sql.Connection; //导入方法依赖的package包/类
public static boolean borradoSprProducto(SprProducto objeto, String usuarioResponsable){
  	 Connection conect=ConnectionConfiguration.conectar();
  	 Statement statement = null;
  	 objeto.changeBorrado();
  	 
	 String query = "update spr_producto set borrado='"+objeto.isBorrado()+"'";
	 		query += ", usuario_responsable='" + usuarioResponsable + "'";	
	 
	 query+=" where id ="+objeto.getId(); 	
	 try {
		statement=conect.createStatement();
		statement.execute(query);
	    conect.close();
	    return true;
	 }catch (SQLException e) {e.printStackTrace(); return false;}
}
 
开发者ID:stppy,项目名称:tcp,代码行数:17,代码来源:SqlUpdates.java

示例10: updateObjetoDeGasto

import java.sql.Connection; //导入方法依赖的package包/类
public static void updateObjetoDeGasto(String id, String nombre,
		String descripcion, String abrev, String es_imputable,
		String numero_fila, String anho) {
	Connection conect = ConnectionConfiguration.conectar();
	Statement statement = null;
	String query = "update objeto_de_gasto set ";
	// if (id!="") query+= "id=\""+id+"\", ";
	if (nombre != "")
		query += "nombre=\"" + nombre + "\", ";
	if (descripcion != "")
		query += "descripcion=\"" + descripcion + "\", ";
	if (abrev != "")
		query += "abrev=\"" + abrev + "\", ";
	if (es_imputable != "")
		query += "es_imputable=\"" + es_imputable + "\", ";
	if (anho != "")
		query += "anho=\"" + anho + "\", ";
	query = query.substring(0, query.length() - 2);
	query += "where id=" + id;

	try {
		statement = conect.createStatement();
		statement.execute(query);
		conect.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
开发者ID:stppy,项目名称:spr,代码行数:29,代码来源:SqlUpdates.java

示例11: selectLaHasAreasAga

import java.sql.Connection; //导入方法依赖的package包/类
public static List<LaHasAreasAga> selectLaHasAreasAga(String conditionLaHasAreasAga) throws SQLException{
	Connection conect=ConnectionConfiguration.conectar();
	String query = " select * from la_has_areas_aga "+conditionLaHasAreasAga;

	Statement statement = null;
	ResultSet rs=null;
	List<LaHasAreasAga> objetos = new ArrayList<LaHasAreasAga>();

	try {
		statement = conect.createStatement();
		rs=statement.executeQuery(query);
		while(rs.next()){
			LaHasAreasAga objeto = new LaHasAreasAga();
	
			objeto.setLineaAccionId(rs.getInt("linea_accion_id"));
			objeto.setAreasAgaId(rs.getInt("areas_aga_id"));
			
			objetos.add(objeto);
		}
	}
	catch (SQLException e) {e.printStackTrace();}
	finally{
		if (statement != null) {statement.close();}
		if (conect != null) {conect.close();}
	}
	return objetos; 
}
 
开发者ID:stppy,项目名称:tcp,代码行数:28,代码来源:SqlSelects.java

示例12: testBug23212347

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for Bug#23212347, ALL API CALLS ON RESULTSET METADATA RESULTS IN NPE WHEN USESERVERPREPSTMTS=TRUE.
 */
public void testBug23212347() throws Exception {
    boolean useSPS = false;
    do {
        String testCase = String.format("Case [SPS: %s]", useSPS ? "Y" : "N");
        createTable("testBug23212347", "(id INT)");

        Properties props = new Properties();
        props.setProperty("useServerPrepStmts", Boolean.toString(useSPS));

        Connection testConn = getConnectionWithProps(props);
        Statement testStmt = testConn.createStatement();
        testStmt.execute("INSERT INTO testBug23212347 VALUES (1)");

        this.pstmt = testConn.prepareStatement("SELECT * FROM testBug23212347 WHERE id = 1");
        this.rs = this.pstmt.executeQuery();
        assertTrue(testCase, this.rs.next());
        assertEquals(testCase, 1, this.rs.getInt(1));
        assertFalse(testCase, this.rs.next());
        ResultSetMetaData rsmd = this.pstmt.getMetaData();
        assertEquals(testCase, "id", rsmd.getColumnName(1));

        this.pstmt = testConn.prepareStatement("SELECT * FROM testBug23212347 WHERE id = ?");
        this.pstmt.setInt(1, 1);
        this.rs = this.pstmt.executeQuery();
        assertTrue(testCase, this.rs.next());
        assertEquals(testCase, 1, this.rs.getInt(1));
        assertFalse(this.rs.next());
        rsmd = this.pstmt.getMetaData();
        assertEquals(testCase, "id", rsmd.getColumnName(1));
    } while (useSPS = !useSPS);
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:35,代码来源:MetaDataRegressionTest.java

示例13: test

import java.sql.Connection; //导入方法依赖的package包/类
public void test() throws Exception {

        Connection conn = newConnection();
        Statement  stmt = conn.createStatement();

        stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS");
        conn.close();

        conn = newConnection();
        stmt = conn.createStatement();

        stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS");
        conn.close();
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:15,代码来源:TestBug808460.java

示例14: selectAllProductosDestinatarios

import java.sql.Connection; //导入方法依赖的package包/类
public static List<ProductoPresupuestoDestinatario> selectAllProductosDestinatarios(String condition) throws SQLException{
 	 Connection conect=ConnectionConfiguration.conectar();
 String query = " select * from producto_presupuesto_destinatario "+condition;
 Statement statement = null;
 ResultSet rs=null;
 List<ProductoPresupuestoDestinatario> objetos = new ArrayList<ProductoPresupuestoDestinatario>();   		 

try {
	statement = conect.createStatement();
	rs=statement.executeQuery(query);
	while(rs.next()){
		ProductoPresupuestoDestinatario objeto = new ProductoPresupuestoDestinatario();
		
		objeto.setId(rs.getInt("id"));
		objeto.setDepartamento(rs.getInt("departamento"));
		objeto.setCantidad(rs.getDouble("cantidad"));
		objeto.setCatalogo_destinatario (rs.getInt("catalogo_destinatario"));
		objeto.setProducto(rs.getShort("producto"));
		objeto.setProyecto(rs.getShort("proyecto"));
		objeto.setSubprograma(rs.getShort("subprograma"));
		objeto.setPrograma(rs.getShort("programa"));
		objeto.setTipo_presupuesto(rs.getShort("tipo_presupuesto"));
		objeto.setEntidad(rs.getShort("entidad"));
		objeto.setNivel(rs.getShort("nivel"));
		objeto.setFechaActualizacion(rs.getTimestamp("fecha_actualizacion"));
		if (rs.getString("descripcion") != null) 
			objeto.setDescripcion((rs.getString("descripcion")));
		objeto.setBorrado(rs.getBoolean("borrado"));
		
		objetos.add(objeto);
	}
}
catch (SQLException e) {e.printStackTrace();}
finally{
	if (statement != null) {statement.close();}
	if (conect != null) {conect.close();}
}
return objetos;
 }
 
开发者ID:stppy,项目名称:spr,代码行数:40,代码来源:SqlSelects.java

示例15: verifyTableColumnContents

import java.sql.Connection; //导入方法依赖的package包/类
private void verifyTableColumnContents(Connection connection,
  String table, String column, ColumnGenerator gen)
    throws IOException, SQLException {
  Statement st = connection.createStatement();

  // create a target database table.
  assertTrue(st.execute("SELECT " + column + " FROM " + table));
  ResultSet rs = st.getResultSet();

  for (int row = 0; rs.next(); ++row) {
    assertEquals(gen.getVerifyText(row), rs.getString(1));
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:14,代码来源:DirectMySQLExportTest.java


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