package com.usoftchina.bi.test.server;

import com.usoftchina.bi.server.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.sql.SQLException;

/**
 * @Author chenwei
 * @Date 2019-04-09
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest( classes = Application.class)
public class GetJavaTypeTest {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Test
    public void getJavaType() throws SQLException {
        //String sql = "select * from employee where em_id = -111009";
        String sql = "select * from (select * from employee where em_id = -111009) where rownum <= 1";
        //String sql = "select 'a' 今天 from dual";
        SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
        SqlRowSetMetaData metaData = rowSet.getMetaData();
        int length = metaData.getColumnCount();
        for (int i = 1; i <= length; i++) {
            System.out.println(metaData.getColumnName(i) + "=" + metaData.getColumnClassName(i).substring(metaData.getColumnClassName(i).lastIndexOf(".") + 1));
        }


        /*System.out.println("==========================分割==========================");
        DatabaseMetaData databaseMetaData = jdbcTemplate.getDataSource().getConnection().getMetaData();
        ResultSet resultSet = databaseMetaData.getColumns(null, databaseMetaData.getUserName(), "EMPLOYEE", "%");
        while (resultSet.next()){
            System.out.println(resultSet.getString("COLUMN_NAME") + "==" + resultSet.getString("TYPE_NAME") + "==" + resultSet.getString("REMARKS"));
        }*/
    }

}
