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


Java ResultSet类代码示例

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


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

示例1: getAssignedUserPrivileges

import java.sql.ResultSet; //导入依赖的package包/类
public static ArrayList<Privilege> getAssignedUserPrivileges(User u) throws Exception {
    ArrayList<Privilege> al = new ArrayList<>();
    String query = "SELECT system_privileges.prv_id, system_privileges.prv_code, "
            + "system_privileges.prv_name, system_privileges.prv_display_name, system_privileges.prv_parent "
            + "FROM user_privileges "
            + "INNER JOIN system_privileges ON user_privileges.prv_id = system_privileges.prv_id "
            + "WHERE user_privileges.user_id = ?";
    PreparedStatement ps = con.prepareStatement(query);
    ps.setInt(1, u.getUserId());
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
        Privilege sp = new Privilege();
        sp.setPrvId(rs.getInt("prv_id"));
        sp.setPrvCode(rs.getString("prv_code"));
        sp.setPrvName(rs.getString("prv_name"));
        sp.setPrvDisplayName(rs.getString("prv_display_name"));
        sp.setPrvParent(rs.getInt("prv_parent"));
        al.add(sp);
    }
    return al;
}
 
开发者ID:isu3ru,项目名称:java-swing-template,代码行数:22,代码来源:UserModel.java

示例2: createAttributes

import java.sql.ResultSet; //导入依赖的package包/类
public static List<Attribute> createAttributes(ResultSet rs) throws SQLException {
    LinkedList attributes = new LinkedList();
    if(rs == null) {
        throw new IllegalArgumentException("Cannot create attributes: ResultSet must not be null!");
    } else {
        ResultSetMetaData metadata;
        try {
            metadata = rs.getMetaData();
        } catch (NullPointerException var7) {
            throw new RuntimeException("Could not create attribute list: ResultSet object seems closed.");
        }

        int numberOfColumns = metadata.getColumnCount();

        for(int column = 1; column <= numberOfColumns; ++column) {
            String name = metadata.getColumnLabel(column);
            Attribute attribute = AttributeFactory.createAttribute(name, getRapidMinerTypeIndex(metadata.getColumnType(column)));
            attributes.add(attribute);
        }

        return attributes;
    }
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:24,代码来源:DatabaseHandler.java

示例3: next

import java.sql.ResultSet; //导入依赖的package包/类
@Override
public DataContainer<ResultSet> next(DataContainer<ResultSet> container) {
       LOGGER.debug("next() called on {}", this);
       if (resultSet == null)
       	return null;
	try {
		if (resultSet.next()) {
			return container.setData(resultSet);
		} else {
			IOUtil.close(this);
			return null;
		}
	} catch (SQLException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:aravindc,项目名称:jdbacl,代码行数:17,代码来源:ResultSetDataIterator.java

示例4: CallableStatementParamInfo

import java.sql.ResultSet; //导入依赖的package包/类
@SuppressWarnings("synthetic-access")
CallableStatementParamInfo(java.sql.ResultSet paramTypesRs) throws SQLException {
    boolean hadRows = paramTypesRs.last();

    this.nativeSql = CallableStatement.this.originalSql;
    this.catalogInUse = CallableStatement.this.currentCatalog;
    this.isFunctionCall = CallableStatement.this.callingStoredFunction;

    if (hadRows) {
        this.numParameters = paramTypesRs.getRow();

        this.parameterList = new ArrayList<CallableStatementParam>(this.numParameters);
        this.parameterMap = new HashMap<String, CallableStatementParam>(this.numParameters);

        paramTypesRs.beforeFirst();

        addParametersFromDBMD(paramTypesRs);
    } else {
        this.numParameters = 0;
    }

    if (this.isFunctionCall) {
        this.numParameters += 1;
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:26,代码来源:CallableStatement.java

示例5: registerUser

import java.sql.ResultSet; //导入依赖的package包/类
public User registerUser(User user) throws Exception {
    try {            
        connect();
        String sql = String.format("CALL register_user('%s', '%s', '%s');", user.getUserName(), user.getEmail(), user.getPassword());                        
        statement = connection.createStatement();            
        ResultSet resultSet = statement.executeQuery(sql);            
        if(resultSet.first()) {
            user.setId(resultSet.getInt("Id"));
            
        } else {
            user = null;
        }            
        disconnect();
        return user;
    } catch (Exception e) {
        throw new Exception("error occured while saving the user data!");
    }
}
 
开发者ID:uclan-projects,项目名称:uclan-messanger,代码行数:19,代码来源:AuthenticationProvider.java

示例6: testSelectFirstOrderByNullsLastGetUndocumentedResult

import java.sql.ResultSet; //导入依赖的package包/类
/**
 * Tests the select order by statement (with nulls last) against all {@linkplain SqlDialect}s
 *
 * @throws SQLException in case of error.
 */
@Test
public void testSelectFirstOrderByNullsLastGetUndocumentedResult() throws SQLException {
  SelectFirstStatement selectOrderByNullsLastStat = selectFirst( field("field2")).from(tableRef("OrderByNullsLastTable")).orderBy(field("field1").desc().nullsLast());

  String sql = convertStatementToSQL(selectOrderByNullsLastStat);

  sqlScriptExecutorProvider.get().executeQuery(sql, new ResultSetProcessor<Void>() {

    @Override
    public Void process(ResultSet resultSet) throws SQLException {
      List<String> expectedResultField2 = Lists.newArrayList("3","4");
      assertTrue(resultSet.next());
      assertTrue(expectedResultField2.contains(resultSet.getString(1)));
      assertFalse(resultSet.next());
      return null;
    };
  });
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:24,代码来源:TestSqlStatements.java

示例7: enhanceIntrospectedTable

import java.sql.ResultSet; //导入依赖的package包/类
/**
 * This method calls database metadata to retrieve some extra information about the table
 * such as remarks associated with the table and the type.
 * 
 * If there is any error, we just add a warning and continue.
 * 
 * @param introspectedTable
 */
private void enhanceIntrospectedTable(IntrospectedTable introspectedTable) {
    try {
        FullyQualifiedTable fqt = introspectedTable.getFullyQualifiedTable();

        ResultSet rs = databaseMetaData.getTables(fqt.getIntrospectedCatalog(), fqt.getIntrospectedSchema(),
                fqt.getIntrospectedTableName(), null);
        if (rs.next()) {
            String remarks = rs.getString("REMARKS"); //$NON-NLS-1$
            String tableType = rs.getString("TABLE_TYPE"); //$NON-NLS-1$
            introspectedTable.setRemarks(remarks);
            introspectedTable.setTableType(tableType);
        }
        closeResultSet(rs);
    } catch (SQLException e) {
        warnings.add(getString("Warning.27", e.getMessage())); //$NON-NLS-1$
    }
}
 
开发者ID:xiachengwei5,项目名称:org.mybatis.generator.core-1.3.5,代码行数:26,代码来源:DatabaseIntrospector.java

示例8: getUserGrantedAuthority

import java.sql.ResultSet; //导入依赖的package包/类
@Override
public List<RolePermission> getUserGrantedAuthority(int userId) {
	String sql = "SELECT * FROM role_permission WHERE userId=?";
	List<RolePermission> roleperms = jdbcInsert.getJdbcTemplate().query(sql, new Object[]{userId}, new RowMapper<RolePermission>() {

		@Override
		public RolePermission mapRow(ResultSet rs, int rowNum) throws SQLException {
			RolePermission roleperm = new RolePermission();
			roleperm.setId(rs.getInt("id"));
			roleperm.setRoleId(rs.getInt("roleId"));
			roleperm.setPermissionId(rs.getInt("permissionId"));
			roleperm.setUserId(rs.getInt("userId"));
			
			return roleperm;
		}
	});
	return roleperms;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:19,代码来源:LoginDaoImpl.java

示例9: testDataSource

import java.sql.ResultSet; //导入依赖的package包/类
@Test
public void testDataSource() throws SQLException {

	assertNotNull(dataSource);

	assertTrue(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource);

	try (Connection c = dataSource.getConnection()) {
		assertNotNull(c);

		try (ResultSet rs = c.createStatement().executeQuery("select str from testx where key=1")) {
			rs.next();
			assertEquals("One", rs.getString(1));
		}
	}

}
 
开发者ID:holon-platform,项目名称:holon-jdbc,代码行数:18,代码来源:TestEnableDataSourceTomcat.java

示例10: testExecuteQueryFilter

import java.sql.ResultSet; //导入依赖的package包/类
@Test
public void testExecuteQueryFilter() throws Exception {
	cleanInsert(Paths.get("src/test/resources/data/setup", "testExecuteQuery.ltsv"));

	List<String> log = TestAppender.getLogbackLogs(() -> {
		SqlContext ctx = agent.contextFrom("example/select_product")
				.paramList("product_id", new BigDecimal("0"), new BigDecimal("2"))
				.param("_userName", "testUserName").param("_funcId", "testFunction").setSqlId("111");
		ctx.setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);

		agent.query(ctx);
	});

	assertThat(log, is(Files.readAllLines(
			Paths.get("src/test/resources/data/expected/AuditLogSqlFilter", "testExecuteQueryFilter.txt"),
			StandardCharsets.UTF_8)));
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:18,代码来源:AuditLogSqlFilterTest.java

示例11: getFromTo

import java.sql.ResultSet; //导入依赖的package包/类
public ResultSet getFromTo(String pfrom_ap,String pto_ap) {
    PreparedStatement pst;
    try {
        String sql = "SELECT * FROM `flight_leg` WHERE `from_aID` = ? AND `to_aID` = ?";
        pst = this.conn.prepareStatement(sql);
        pst.setString(1, pfrom_ap);
        pst.setString(2, pto_ap);
        ResultSet rs;
        rs = pst.executeQuery();
        return rs;
    } catch (SQLException e) {
        System.out.println("Error : while excicuting prepared statement");
        System.out.println(e);
        return null;
    }
}
 
开发者ID:YasasshraSolutions,项目名称:Java-Air-Reservation,代码行数:17,代码来源:FlightLeg.java

示例12: getNewToolContentId

import java.sql.ResultSet; //导入依赖的package包/类
private long getNewToolContentId(long newToolId, Connection conn) throws DeployException {
PreparedStatement stmt = null;
ResultSet results = null;
try {
    stmt = conn.prepareStatement("INSERT INTO lams_tool_content (tool_id) VALUES (?)");
    stmt.setLong(1, newToolId);
    stmt.execute();
    stmt = conn.prepareStatement("SELECT LAST_INSERT_ID() FROM lams_tool_content");
    results = stmt.executeQuery();
    if (results.next()) {
	return results.getLong("LAST_INSERT_ID()");
    } else {
	throw new DeployException("No tool content id found");
    }

} catch (SQLException sqlex) {
    throw new DeployException("Could not get new tool content id", sqlex);
} finally {
    DbUtils.closeQuietly(stmt);
    DbUtils.closeQuietly(results);
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:ToolDBDeployTask.java

示例13: executeSingleResultQuery

import java.sql.ResultSet; //导入依赖的package包/类
private Object executeSingleResultQuery(String query, Map<?, ?> params)
{
	return jdbcTemplate.query(query, params, new ResultSetExtractor()
	{
		@Override
		public Object extractData(ResultSet rs) throws SQLException, DataAccessException
		{
			Object data = null;
			if( rs.next() )
			{
				data = rs.getObject(1);

				// Sanity check - ensure only a single result
				if( rs.next() )
				{
					throw new IncorrectResultSizeDataAccessException(1);
				}
			}
			return data;
		}
	});
}
 
开发者ID:equella,项目名称:Equella,代码行数:23,代码来源:SqlTaxonomyDataSource.java

示例14: getPermissions

import java.sql.ResultSet; //导入依赖的package包/类
@Override
public List<Permission> getPermissions() {
	String sql = "SELECT * FROM permission";
	List<Permission> perms = jdbcInsert.getJdbcTemplate().query(sql,  new RowMapper<Permission>() {

		@Override
		public Permission mapRow(ResultSet rs, int rowNum) throws SQLException {
			Permission perm = new Permission();
			perm.setId(rs.getInt("id"));
			perm.setName(rs.getString("name"));
		    perm.setDescription(rs.getString("description"));

			return perm;
		}
	});
	
	return perms;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:19,代码来源:LoginDaoImpl.java

示例15: demo3_execute_insert

import java.sql.ResultSet; //导入依赖的package包/类
private static void demo3_execute_insert(){
    executeUpdate("delete from enums where id < 7"); //to make the demo re-runnable

    System.out.println();
    try (Connection conn = getDbConnection()) {
        try (Statement st = conn.createStatement()) {
            boolean res = st.execute("insert into enums (id, type, value) values(1,'vehicle','car')");
            if (res) {
                ResultSet rs = st.getResultSet();
                while (rs.next()) {
                    int id = rs.getInt(1); //More efficient than rs.getInt("id")
                    String type = rs.getString(2);
                    String value = rs.getString(3);
                    System.out.println("id = " + id + ", type = " + type + ", value = " + value);
                }
            } else {
                int count = st.getUpdateCount();
                System.out.println("Update count = " + count);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:25,代码来源:Chapter06Database01.java


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