How do you get values from all columns using ResultSet.getBinaryStream() in jdbc?

You can get all the column names and the entire data from your table using the code below. writeToFile method will contain the logic to writing to file (if that was not obvious enough 🙂 ) ResultSetMetaData metadata = rs.getMetaData(); int columnCount = metadata.getColumnCount(); for (int i = 1; i <= columnCount; i++) { writeToFile(metadata.getColumnName(i) … Read more

DB2 Comma Separated Output by Groups

LISTAGG function is new function in DB2 LUW 9.7 see example: create table myTable (id int, category int); insert into myTable values (1, 1); insert into myTable values (2, 2); insert into myTable values (5, 1); insert into myTable values (3, 1); insert into myTable values (4, 2); example: select without any order in grouped … Read more

db2 SQLCODE -668 when inserting

To add to James’ answer and save people time looking around, you could execute CALL SYSPROC.ADMIN_CMD(‘REORG TABLE MY_TABLE_NAME’) via any available SQL client (i.e. even over ODBC or JDBC connection) to rectify this problem. However, the connection has to be in autocommit mode and you have to have admin privileges to execute this command. I … Read more

Declare a variable in DB2 SQL

I assume this forum posting, which I quote fully below, should answer the question. Inside a procedure, function, or trigger definition, or in a dynamic SQL statement (embedded in a host program): BEGIN ATOMIC DECLARE example VARCHAR(15) ; SET example=”welcome” ; SELECT * FROM tablename WHERE column1 = example ; END or (in any environment): … Read more

insert multiple rows into DB2 database

I’m assuming you’re using DB2 for z/OS, which unfortunately (for whatever reason, I never really understood why) doesn’t support using a values-list where a full-select would be appropriate. You can use a select like below. It’s a little unwieldy, but it works: INSERT INTO tableName (col1, col2, col3, col4, col5) SELECT val1, val2, val3, val4, … Read more

tech