Not able to perform query using vertx-db2-client with Spring Boot and getting error
I'm trying to connect and query to DB2 using vertx-db2-client, but it is not working. I'm using Spring Boot 2.6.6 and vertx-db2-client library to perform query in reactive way. I've created a class which implements CommandLineRunner
Dependency in my build.gradle
implementation 'io.vertx:vertx-db2-client:4.2.6'
implementation 'io.vertx:vertx-reactive-streams:4.2.6'
Below is my CommandLineRunner class.
import io.vertx.db2client.DB2ConnectOptions;
import io.vertx.db2client.DB2Pool;
import io.vertx.sqlclient.PoolOptions;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.SqlClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;
@Configuration
@Slf4j
public class DB2DataLoader implements CommandLineRunner {
/**
* Callback used to run the bean.
*
* @param args incoming main method arguments
* @throws Exception on error
*/
@Override
public void run(String... args) throws Exception {
DB2ConnectOptions connectOptions =
new DB2ConnectOptions()
.setPort(50001)
.setHost("db_host_name")
.setDatabase("db_name")
.setUser("username")
.setPassword("password");
// Pool options
PoolOptions poolOptions = new PoolOptions().setMaxSize(5);
// Create the client pool
SqlClient client = DB2Pool.client(connectOptions, poolOptions);
// A simple query
client
.query("SELECT * FROM SCHEMA.TABLE")
.execute(
ar -> {
if (ar.succeeded()) {
RowSet<Row> result = ar.result();
System.out.println("Got " + result.size() + " rows ");
} else {
System.out.println("Failure: " + ar.cause().getMessage());
}
// Now close the pool
client.close();
});
}
}
I'm not seeing any connection issues. The error that I see right after the deployment is below:
2022-04-11 15:35:11.740 INFO 2736 --- [ main] c.h.t.p.ServiceApp : Started ServiceApp in 3.746 seconds (JVM running for 4.719)
Failure: SQLState.NET_VCM_VCS_LENGTHS_INVALID: VCM and VCS lengths are mutually exclusive but both were set: vcsLen=255 vcmLen=12336
I'm not sure what this "Failure: **" means. Database connection parameters are correct. I've just masked here. I was following https://vertx.io/docs/vertx-db2-client/java/#_getting_started documentation for the example.
Before creating this issue, I've asked this question in stackoverflow.com https://stackoverflow.com/questions/71834149/not-able-to-perform-query-using-vertx-db2-client-with-spring-boot-and-getting-er?noredirect=1#comment126950541_71834149
cc @mswatosh does that ring a bell?
Unfortunately not something I've seen before...
@anish-panthi Can you test if this still occurs outside of Spring? I'm not particularly familiar with Spring, but this essentially looks like a Runnable, so don't think it would be interfering, but probably worth a quick test.
Also, can you let me know which OS and Version of Db2 you're running against? (Or if you're using the container)
I'll do some looking into VCS and VCM, since it looks like this is an invalid response from the Database, but it's possible we're parsing something incorrectly, or this is a now a valid case we should handle.
@mswatosh I got the same error using plain Gradle Project:
12:19:32 PM: Executing ':DB2ConnectionTest.main()'...
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :DB2ConnectionTest.main()
[vert.x-eventloop-thread-0] ERROR *** Error: java.lang.IllegalStateException: SQLState.NET_VCM_VCS_LENGTHS_INVALID: VCM and VCS lengths are mutually exclusive but both were set: vcsLen=255 vcmLen=12336
DB2 Version: 11 (Major) OS: Linux Java Version: 17 Gradle Version: 7.2
We are using DB2 on mainframe and seeing this issue as well.
any update on this? Need help .
This is outside spring.
connecting to remote db2
implementation(platform("io.vertx:vertx-stack-depchain:4:3.1"))
implementation "io.vertx:vertx-db2-client"
implementation "io.vertx:vertx-rx-java3"
ERROR [vert.x-eventloop-thread-2] ?: FATAL: Error parsing buffer at index 828 / 0x33c
java.lang.IllegalStateException: SQLState.NET_VCM_VCS_LENGTHS_INVALID: VCM and VCS lengths are mutually exclusive but both were set: vcsLen=16735 vcmLen=548 at io.vertx.db2client.impl.drda.DRDAResponse.parseFastVCMorVCS(DRDAResponse.java:755) at io.vertx.db2client.impl.drda.DRDAQueryResponse.parseSQLDOPTGRP(DRDAQueryResponse.java:3215) at io.vertx.db2client.impl.drda.DRDAQueryResponse.parseSQLDAGRP(DRDAQueryResponse.java:3187) at io.vertx.db2client.impl.drda.DRDAQueryResponse.parseSQLDAROW(DRDAQueryResponse.java:3111) at io.vertx.db2client.impl.drda.DRDAQueryResponse.parseSQLDARDarray(DRDAQueryResponse.java:3090) at io.vertx.db2client.impl.drda.DRDAQueryResponse.parseSQLDARD(DRDAQueryResponse.java:3027) at io.vertx.db2client.impl.drda.DRDAQueryResponse.parsePRPSQLSTTreply(DRDAQueryResponse.java:2448) at io.vertx.db2client.impl.drda.DRDAQueryResponse.readPrepareDescribeOutput(DRDAQueryResponse.java:47) at io.vertx.db2client.impl.codec.SimpleQueryCommandCodec.decodeQuery(SimpleQueryCommandCodec.java:75) at io.vertx.db2client.impl.codec.QueryCommandBaseCodec.decodePayload(QueryCommandBaseCodec.java:69) at io.vertx.db2client.impl.codec.DB2Decoder.decodePayload(DB2Decoder.java:79) at io.vertx.db2client.impl.codec.DB2Decoder.decode(DB2Decoder.java:52)