Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

phoenix wide table, insert 1 row with 100 columns

avatar
New Member

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.