Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

phoenix wide table, insert 1 row with 100 columns

avatar
Contributor

Hi,

I am using spring boot jdbc template connecting to a phoenix hbase database.

However, i have a table with 100 columns. so, everytime when i insert a row should contain 100 values

For example insert:

	public void insert(Ttsnihl m){
		Object[] params = new Object[]{
				m.getPATIENT_ID(), 
                m.getRECORD_DATE(),
                m.getSTART_TIME(),
                m.getEND_TIME(),
                .....// 100 object array
               };
		jdbcTemplate.update(insertSql, params);
	}

And:

	public void insertBatch(final List<Ttsnihl> ts){
		
		BatchPreparedStatementSetter bpss = new BatchPreparedStatementSetter() {
			@Override
			public void setValues(PreparedStatement ps, int i) throws SQLException {
				Ttsnihl t=ts.get(i);
				ps.setString(1,  t.getPATIENT_ID());
				ps.setTimestamp(2,  t.getRECORD_DATE());
				ps.setTimestamp(3, t.getSTART_TIME());
				ps.setTimestamp(4, t.getEND_TIME());
                                ..... // 100 ps.set()functions
                                
			}
			@Override
		    public int getBatchSize() {
		        return ts.size();
		    }
		  };
		  
		jdbcTemplate.batchUpdate(insertSql, bpss);
	}

I want to ask, is there any smart way to do this?

Many thanks in advance!

1 ACCEPTED SOLUTION

avatar
Super Guru

No, if you need to store 100 columns per row, you need to set the values on the prepared statement for each row.

View solution in original post

1 REPLY 1

avatar
Super Guru

No, if you need to store 100 columns per row, you need to set the values on the prepared statement for each row.