Java 8 ResultSetMetaData - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ResultSetMetaData class.

This code example shows how to use the following methods:isWritable
     * fail, Failing statements commented out. Feature only partially 
     * implemented. 
     */ 
    public void testIsWritable() { 
        try { 
            assertTrue(rsmd.isWritable(1));
            assertTrue(rsmd.isWritable(2));
            assertTrue(rsmd.isWritable(3));
        } catch (SQLException e1) {
            fail("ResultSetMetaDataTest.isWritable" + e1.getMessage());
            e1.printStackTrace();
        } 
 
        // Exception testing 
 
        try { 
            rsmd.isWritable(0);
            fail("SQLException is not thrown"); 
        } catch (SQLException e) {
            // expected 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getColumnCount
 
		expect(connection.getUnderlyingConnection()).andReturn(sqlConnection).anyTimes();
		expect( sqlConnection.createStatement()).andReturn(statement);
		expect( statement.executeQuery("SELECT CONVERT(varchar(100), SERVERPROPERTY('COLLATION'))")).andReturn(resultSet);
		expect( resultSet.next() ).andReturn(true);
		expect( resultSet.getMetaData() ).andReturn(metadata);
		expect( metadata.getColumnCount() ).andReturn(1);
		expect( resultSet.getString(1)).andReturn(collation);
		expect( resultSet.next() ).andReturn(false);
 
		connection.attached(database);
		replay(connection, sqlConnection, statement, resultSet, metadata);
		database.setConnection(connection);
		return database;
    } 
     
    @Test
    public void caseSensitiveBinaryCollation() throws Exception {
    	Database database =  getADatabaseWithCollation("Latin1_General_BIN");
    	assertTrue( "Should be case sensitive", database.isCaseSensitive() );
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getColumnName, getColumnType
     */ 
    public void process(Table t, int trow, ResultSet rset, int rcol)
        throws SQLException 
    { 
        ResultSetMetaData metadata = rset.getMetaData();
        String field = metadata.getColumnName(rcol);
        int type = metadata.getColumnType(rcol);
         
        switch ( type ) {
        case Types.ARRAY:
            t.set(trow, field, rset.getArray(rcol));
            break; 
             
        case Types.BIGINT:
            t.setLong(trow, field, rset.getLong(rcol));
            break; 
             
        case Types.BINARY:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCatalogName, getColumnClassName, getColumnName, getColumnType, getColumnTypeName
This code example shows how to use the following methods:getColumnClassName
        } 
    } 
 
    public void testGetColumnClassName() { 
        try { 
            assertNotNull(rsmd);
            assertEquals(Short.class.getName(), rsmd.getColumnClassName(1));
            assertEquals(String.class.getName(), rsmd.getColumnClassName(2));
            assertEquals(String.class.getName(), rsmd.getColumnClassName(3));
        } catch (SQLException e) {
            fail("SQLException is thrown: " + e.getMessage());
        } 
 
        try { 
            String name  = rsmd.getColumnClassName(0);
            assertNull(name);
        } catch (SQLException e) {
            fail("SQLException is thrown"); 
        } 
 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getColumnCount, getColumnName
 
    @Test 
    public void differentRS() throws SQLException 
    { 
        meta = stat.executeQuery("select * from people;").getMetaData();
        assertEquals(meta.getColumnCount(), 4);
        assertEquals(meta.getColumnName(1), "pid");
        assertEquals(meta.getColumnName(2), "firstname");
        assertEquals(meta.getColumnName(3), "surname");
        assertEquals(meta.getColumnName(4), "dob");
    } 
 
    @Test 
    public void nullable() throws SQLException 
    { 
        meta = stat.executeQuery("select null;").getMetaData();
        assertEquals(meta.isNullable(1), ResultSetMetaData.columnNullable);
    } 
 
    @Test(expected = SQLException.class) 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getColumnCount, getColumnName
    } 
     
    private ResultSet getTestResultSet() throws SQLException {
         
        ResultSetMetaData rsm = createMock( ResultSetMetaData.class );
        expect( rsm.getColumnCount() ).andReturn( 2 );
        expect( rsm.getColumnName(1) ).andReturn("name");
        expect( rsm.getColumnName(2) ).andReturn("another");
        replay( rsm );
         
        ResultSet rs = createMock( ResultSet.class );
        expect( rs.next() ).andReturn( true );
        expect( rs.getMetaData() ).andReturn( rsm ).times( 1 );
        expect( rs.getString("name") ).andReturn("value").times( 1 );
        expect( rs.getString("another") ).andReturn("some & value < >").times( 1 );
        expect( rs.next() ).andReturn( false );
        rs.close();
        replay( rs );
         
        return rs;
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getColumnCount, getColumnTypeName
	@Override 
	@SuppressWarnings("unchecked") 
	public T mapRow(ResultSet rs, int rowNum) throws SQLException {
		// Validate column count. 
		ResultSetMetaData rsmd = rs.getMetaData();
		int nrOfColumns = rsmd.getColumnCount();
		if (nrOfColumns != 1) {
			throw new IncorrectResultSetColumnCountException(1, nrOfColumns);
		} 
 
		// Extract column value from JDBC ResultSet. 
		Object result = getColumnValue(rs, 1, this.requiredType);
		if (result != null && this.requiredType != null && !this.requiredType.isInstance(result)) {
			// Extracted value does not match already: try to convert it. 
			try { 
				return (T) convertValueToRequiredType(result, this.requiredType);
			} 
			catch (IllegalArgumentException ex) {
				throw new TypeMismatchDataAccessException( 
						"Type mismatch affecting row number " + rowNum + " and column type '" +

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getColumnCount, getColumnType
        ResultSetMetaData md;
 
        // special-column as functions 
        rs = s.executeQuery("SELECT CURRENT_DATE, CURRENT_DATE(), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(), CURRENT_TIME, CURRENT_TIME()");
        md = rs.getMetaData();
        assertEquals(6, md.getColumnCount());
        assertEquals(Types.DATE, md.getColumnType(1));
        assertEquals(Types.DATE, md.getColumnType(2));
        assertEquals(Types.TIMESTAMP, md.getColumnType(3));
        assertEquals(Types.TIMESTAMP, md.getColumnType(4));
        assertEquals(Types.TIME, md.getColumnType(5));
        assertEquals(Types.TIME, md.getColumnType(6));
 
        // double quote as string 
        rs = s.executeQuery("SELECT \"foo\"");
        assertTrue(rs.next());
        assertEquals("foo", rs.getString(1));
 
        // infix bit operators 
        rs = s.executeQuery("SELECT 1|2");
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getColumnName
	} 
 
	@Override 
	public String getColumnName(int column) throws InvalidResultSetAccessException { 
		try { 
			return this.resultSetMetaData.getColumnName(column); 
		} 
		catch (SQLException se) { 
			throw new InvalidResultSetAccessException(se); 
		} 
	} 
 
	@Override 
	public int getColumnType(int column) throws InvalidResultSetAccessException { 
		try { 
			return this.resultSetMetaData.getColumnType(column); 
		} 
		catch (SQLException se) { 
			throw new InvalidResultSetAccessException(se); 
		} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 ResultSetMetaData Questions & Answers:

See Code Examples for Java 8 ResultSetMetaData Methods: