當前位置: 首頁>>代碼示例>>Java>>正文


Java NamedParameterJdbcTemplate.queryForObject方法代碼示例

本文整理匯總了Java中org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject方法的典型用法代碼示例。如果您正苦於以下問題:Java NamedParameterJdbcTemplate.queryForObject方法的具體用法?Java NamedParameterJdbcTemplate.queryForObject怎麽用?Java NamedParameterJdbcTemplate.queryForObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate的用法示例。


在下文中一共展示了NamedParameterJdbcTemplate.queryForObject方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tableExists

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
public static boolean tableExists(NamedParameterJdbcTemplate namedParameterJdbcTemplate, String tableName) throws PostgresException {
    String sql = "SELECT EXISTS (\n"
            + "    SELECT 1 \n"
            + "    FROM   pg_catalog.pg_class c\n"
            + "    JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
            + "    WHERE  n.nspname = 'public'\n"
            + "    AND    c.relname = :table_name\n"
            + ")";

    SqlParameterSource paramSource = new MapSqlParameterSource("table_name", tableName);
    try {
        return namedParameterJdbcTemplate.queryForObject(sql, paramSource, Boolean.class);
    } catch (DataAccessException e) {
        throw new PostgresException(String.format("Error while checking if table [%s] exists", tableName), e);
    }
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:17,代碼來源:PostgresHelper.java

示例2: removeTestFormData

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private void removeTestFormData() {
	NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource);
	
	int formId = -1;
	try {
		formId = template.queryForObject("select formid from form where formid=:formid", 
				new MapSqlParameterSource("formid", 9999), Integer.class);
	} catch(Exception e) {
		System.out.println("Failed to get formId, not removing form!");
		return;
	}
	System.out.println("\n!!!Retrieve test form ID result: " + formId);
			
	
	int formResult = template.update("delete from form where formid=:formid",
			new MapSqlParameterSource("formid", formId));
	System.out.println("\n!!!Remove test Form result: " + formResult);
}
 
開發者ID:hadrsystems,項目名稱:nics-common,代碼行數:19,代碼來源:NicsDaoTest.java

示例3: selecteerMinMaxIdVoorSelectie

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
@Override
public MinMaxPersoonCacheDTO selecteerMinMaxIdVoorSelectie() {
    final String sql
            = "select min(id) as laag, max(id) as hoog from kern.perscache";
    final NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(selectieDataSource);
    final Map<String, Object> parameters = new HashMap<>();
    return jdbcTemplate.queryForObject(sql, parameters, (resultSet, i) -> {
        final MinMaxPersoonCacheDTO minMaxPersoonCacheDTO = new MinMaxPersoonCacheDTO();
        minMaxPersoonCacheDTO.setMinId(resultSet.getInt("laag"));
        minMaxPersoonCacheDTO.setMaxId(resultSet.getInt("hoog"));
        return minMaxPersoonCacheDTO;
    });
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:14,代碼來源:PersoonCacheSelectieJpaRepositoryImpl.java

示例4: removeTestUserData

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; //導入方法依賴的package包/類
private void removeTestUserData() {
	NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource);
	
	long userId = -1;
	try {
		userId = template.queryForObject("select userid from public.user where username=:username", 
				new MapSqlParameterSource("username", "[email protected]"), Long.class);
	} catch(Exception e) {
		System.out.println("Failed to get userId, not removing any other test data");
		return;
	}
	System.out.println("\n!!!Retrieve test user ID result: " + userId);
	
	if(userId < 1) {
		System.out.println("Invalid userId: " + userId + ", not removing any further test data");
		return;
	}
	
	int contactResult = template.update("delete from contact where userid=:userid",
			new MapSqlParameterSource("userid", userId));
	System.out.println("\n!!!Remove test Contacts result: " + contactResult);
	
	int userorgResult = template.update("delete from userorg where userid=:userid",
			new MapSqlParameterSource("userid", userId));
	System.out.println("\n!!!Remove userorgs result: " + userorgResult);
	
	int userResult = template.update("delete from public.user where username=:username", 
			new MapSqlParameterSource("username", "[email protected]"));		
	System.out.println("\n!!!Remove test user result: " + userResult);
	
	// TODO: remove contacts and userorg, etc
	
}
 
開發者ID:hadrsystems,項目名稱:nics-common,代碼行數:34,代碼來源:NicsDaoTest.java


注:本文中的org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。