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


Java Connection.close方法代码示例

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


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

示例1: close

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Close connection
 *
 * @param rs
 */
public static void close(ResultSet rs) {
    Statement st = null;
    Connection con = null;
    try {
        try {
            if (rs != null) {
                st = rs.getStatement();
                rs.close();
            }
        } finally {
            try {
                if (st != null) {
                    con = st.getConnection();
                    st.close();
                }
            } finally {
                if (con != null) {
                    con.close();
                }
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:31,代码来源:JDBCUtils.java

示例2: testBug12975

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#12975 - OpenOffice expects DBMD.supportsIEF() to return
 * "true" if foreign keys are supported by the datasource, even though this
 * method also covers support for check constraints, which MySQL _doesn't_
 * have.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug12975() throws Exception {
    assertEquals(false, this.conn.getMetaData().supportsIntegrityEnhancementFacility());

    Connection overrideConn = null;

    try {
        Properties props = new Properties();

        props.setProperty("overrideSupportsIntegrityEnhancementFacility", "true");

        overrideConn = getConnectionWithProps(props);
        assertEquals(true, overrideConn.getMetaData().supportsIntegrityEnhancementFacility());
    } finally {
        if (overrideConn != null) {
            overrideConn.close();
        }
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:28,代码来源:MetaDataRegressionTest.java

示例3: deleteTipoObjetivo

import java.sql.Connection; //导入方法依赖的package包/类
public static void deleteTipoObjetivo(String id){
 	 Connection conect=ConnectionConfiguration.conectar();
 	 Statement statement = null;
 String 				query = "delete from tipo_objetivo ";
 //if (id!="")			query+= "id=\""+id+"\", ";
 /*if (nombre!="")		query+= "nombre=\""+nombre+"\", ";
 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,代码行数:17,代码来源:SqlDelete.java

示例4: IGuildSettings

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Create a {@link GuildSettings} instance
 * @param guild The Guild those settings are being linked to.
 * @param bot A {@link LegendaryBot} instance.
 */
public IGuildSettings(Guild guild, LegendaryBot bot) {
    this.bot = bot;
    this.guildId = guild.getId();
    try {
        Connection conn = bot.getDatabase().getConnection();
        PreparedStatement statement = conn.prepareStatement("SELECT configName,configValue FROM guild_config WHERE guildId=?");
        statement.setString(1, guildId);
        ResultSet set = statement.executeQuery();
        while (set.next()) {
            settings.put(set.getString("configName"),set.getString("configValue"));
        }
        set.close();
        statement.close();
        conn.close();
    } catch (SQLException e) {
        e.printStackTrace();
        bot.getStacktraceHandler().sendStacktrace(e, "guildId:" + guildId);
    }
}
 
开发者ID:greatman,项目名称:legendarybot,代码行数:25,代码来源:IGuildSettings.java

示例5: borradoAvanceCosto

import java.sql.Connection; //导入方法依赖的package包/类
public static boolean borradoAvanceCosto(AvanceCosto objeto, String usuarioResponsable){
  	 Connection conect=ConnectionConfiguration.conectar();
  	 Statement statement = null;
  	 objeto.changeBorrado();
  	 
	 String query = "update avance_costo 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,代码行数:18,代码来源:SqlUpdates.java

示例6: insertFuenteFinanciamietno

import java.sql.Connection; //导入方法依赖的package包/类
public static void insertFuenteFinanciamietno(int numero_fila,int anho,int id,String nombre, String descripcion){
 	 Connection conect=conectar();
 String query = " insert into fuente_financiamiento (numero_fila,anho,id,nombre,descripcion)"
	        + " values (?,?,?,?,?)";
try {
	
	PreparedStatement preparedStmt;
	preparedStmt = conect.prepareStatement(query);
	preparedStmt.setInt (1, numero_fila);
	preparedStmt.setInt (2,anho);
	preparedStmt.setInt (3, id);
	preparedStmt.setString (4, nombre);
	preparedStmt.setString (5, descripcion);
    preparedStmt.execute();
    conect.close();
} catch (SQLException e) {e.printStackTrace();}
 }
 
开发者ID:stppy,项目名称:spr,代码行数:18,代码来源:SqlHelper.java

示例7: insertPilares

import java.sql.Connection; //导入方法依赖的package包/类
public static void insertPilares(int id,  String nombre, String descripcion, int numero_fila, int eje, int linea){
 	 Connection conect=conectar();
 String query = " insert into estrategia (id, nombre, descripcion, numero_fila, eje_estrategico_id,  linea_transversal_id)"
	        + " values (?,?,?,?,?,?)";
try {
	
	PreparedStatement preparedStmt;
	preparedStmt = conect.prepareStatement(query);
	preparedStmt.setInt (1, id);
	preparedStmt.setString (2, nombre);
	preparedStmt.setString (3, descripcion);
	preparedStmt.setInt (4, numero_fila);
	preparedStmt.setInt (5, eje);
	preparedStmt.setInt (6, linea);
    preparedStmt.execute();
    conect.close();
} catch (SQLException e) {e.printStackTrace();}
 }
 
开发者ID:stppy,项目名称:tcp,代码行数:19,代码来源:SqlHelper.java

示例8: testBug40439

import java.sql.Connection; //导入方法依赖的package包/类
public void testBug40439() throws Exception {
    Connection conn2 = null;
    try {
        createTable("testBug40439VALUES", "(x int)");
        conn2 = getConnectionWithProps("rewriteBatchedStatements=true");
        PreparedStatement ps = conn2.prepareStatement("insert into testBug40439VALUES (x) values (?)");
        ps.setInt(1, 1);
        ps.addBatch();
        ps.setInt(1, 2);
        ps.addBatch();
        ps.executeBatch();
    } finally {
        if (conn2 != null) {
            try {
                conn2.close();
            } catch (SQLException ex) {
            }
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:21,代码来源:StatementRegressionTest.java

示例9: testBug54095

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#54095 - Unnecessary call in newSetTimestampInternal.
 *
 * This bug was fixed as a consequence of the patch for Bug#71084.
 *
 * @throws Exception
 *             if the test fails.
 */
public void testBug54095() throws Exception {
    Connection testConn = getConnectionWithProps("useLegacyDatetimeCode=false");

    Calendar testCal = Calendar.getInstance();
    java.util.Date origDate = testCal.getTime();

    PreparedStatement testPstmt = testConn.prepareStatement("SELECT ?");
    testPstmt.setTimestamp(1, new Timestamp(0), testCal);
    assertEquals("Calendar object shouldn't have changed after PreparedStatement.setTimestamp().", origDate, testCal.getTime());

    ResultSet testRs = testPstmt.executeQuery();
    testRs.next();
    assertEquals("Calendar object shouldn't have changed after PreparedStatement.executeQuery().", origDate, testCal.getTime());

    testRs.getTimestamp(1, testCal);
    assertEquals("Calendar object shouldn't have changed after ResultSet.getTimestamp().", origDate, testCal.getTime());

    testRs.close();
    testPstmt.close();
    testConn.close();
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:30,代码来源:StatementRegressionTest.java

示例10: testShouldAddSpanForPreparedStatementExecuteUpdate

import java.sql.Connection; //导入方法依赖的package包/类
@Test
public void testShouldAddSpanForPreparedStatementExecuteUpdate() throws Exception {
    Connection connection = dataSource.getConnection();
    connection.prepareStatement("UPDATE INFORMATION_SCHEMA.TABLES SET table_Name = '' WHERE 0 = 1").executeUpdate();
    connection.close();

    assertThat(ExceptionUtils.getLastException()).isNull();

    assertThat(spanReporter.getSpans()).hasSize(2);
    Span connectionSpan = spanReporter.getSpans().get(0);
    Span statementSpan = spanReporter.getSpans().get(1);
    assertThat(connectionSpan.getName()).isEqualTo("jdbc:/dataSource/connection");
    assertThat(statementSpan.getName()).isEqualTo("jdbc:/dataSource/query");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_SQL_QUERY_TAG_NAME, "UPDATE INFORMATION_SCHEMA.TABLES SET table_Name = '' WHERE 0 = 1");
    assertThat(statementSpan.tags()).containsEntry(SleuthListenerAutoConfiguration.SPAN_ROW_COUNT_TAG_NAME, "0");
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:TracingQueryExecutionListenerTests.java

示例11: findAllTables

import java.sql.Connection; //导入方法依赖的package包/类
public List<String> findAllTables(String dataSourceName) throws Exception {
	List<String> tablesList = new ArrayList<String>();
	Connection conn = null;
	ResultSet rs = null;
	try {
		conn = connectionHelper.getConnection(dataSourceName);
		DatabaseMetaData metaData = conn.getMetaData();
		String url = metaData.getURL();
		String schema = null;
		if (url.toLowerCase().contains("oracle")) {
			schema = metaData.getUserName();
		}
		rs = metaData.getTables(null, schema, "%", new String[] { "TABLE" });
		while (rs.next()) {
			tablesList.add(rs.getString("TABLE_NAME").toLowerCase());
		}
		return tablesList;
	} finally {
		if (conn != null) {
			conn.close();
		}
		if (rs != null) {
			rs.close();
		}
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:27,代码来源:ExcelModelManager.java

示例12: recycleConnection

import java.sql.Connection; //导入方法依赖的package包/类
@Override
public void recycleConnection(Connection connection) throws SQLException {
	try {
		connection.close();
	} catch (Exception e) {
		log.error("recycleConnection exception", e);
	}
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:9,代码来源:DBCPDataSource.java

示例13: actAvanceCosto

import java.sql.Connection; //导入方法依赖的package包/类
public static boolean actAvanceCosto(AvanceCosto objeto, String usuarioResponsable){
 try {
	 Connection conect=ConnectionConfiguration.conectar();
	 String query = "update avance_costo set ";
	 PreparedStatement update =null;

	 	if(objeto.getMonto()!=0) 				query+= "monto= ?";
		if(objeto.getCodigoContratacion()!=null)query+= ", codigo_contratacionl= ?";
		if(objeto.getObjetoGasto()!=0)  		query+= ", objeto_gasto= ?";
		if(objeto.getAvanceId()!=0)      		query+= ", avance_id= ?";
												query += ", usuario_responsable = ? ";

		query+=" where id = ?";

		int cantCampos =0;
		update = conect.prepareStatement(query);
		if (objeto.getMonto()!=0) 					{    cantCampos++;update.setDouble (cantCampos, objeto.getMonto());}
		if (objeto.getCodigoContratacion()!=null)	{    cantCampos++;update.setString (cantCampos, objeto.getCodigoContratacion());}
		if (objeto.getObjetoGasto()!=0)     		{    cantCampos++;update.setInt (cantCampos, objeto.getObjetoGasto());}
		if (objeto.getAvanceId()!=0)        		{    cantCampos++;update.setInt	(cantCampos, objeto.getAvanceId());}
				
			cantCampos++;
			update.setString (cantCampos, usuarioResponsable);
		
            cantCampos++;
            update.setInt    (cantCampos , objeto.getId());

            update.execute();
			conect.close();
	    return true;
	} catch (SQLException e) {e.printStackTrace(); return false;}
}
 
开发者ID:stppy,项目名称:tcp,代码行数:33,代码来源:SqlUpdates.java

示例14: isNoticeEnabled

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * @return Returns the noticeEnabled.
 */
public boolean isNoticeEnabled()
{
 String result="";
 Connection con = null;
 try
 {
    
	 con = L2DatabaseFactory.getInstance().getConnection();
	 PreparedStatement statement = con.prepareStatement("SELECT enabled FROM clan_notices WHERE clanID=?");
	 statement.setInt(1, getClanId());
	 ResultSet rset = statement.executeQuery();
    
	 while (rset.next())
	 {
		 result = rset.getString("enabled");
	 }
    
	 rset.close();
	 statement.close();
	 con.close();
    
 } catch (Exception e)
 {
	 if (Config.DEBUG)
	 System.out.println("BBS: Error while reading _noticeEnabled for clan "+ this.getClanId() + "");
	 if(e.getMessage()!=null)
		 if (Config.DEBUG) 
		 System.out.println("BBS: Exception = "+e.getMessage()+"");
 }
 if (result.isEmpty())
 {
	 insertNotice();
	 return false;
 }
 else if(result.compareToIgnoreCase("true")==0)
	 return true;
 else
	 return false;
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:43,代码来源:L2Clan.java

示例15: executeUpdateQueryFromResource

import java.sql.Connection; //导入方法依赖的package包/类
public static void executeUpdateQueryFromResource(Connection connection, String resourceName) {
    URL resource = JDBCUtil.class.getResource(resourceName);
    try {
        String query = Resources.toString(resource, Charsets.UTF_8);
        try (Statement statement = connection.createStatement()) {
            statement.executeUpdate(query);
        }
        connection.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:13,代码来源:JDBCUtil.java


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