ResultSetImpl throws a NullPointerException

I am running mysql 5.5 using the mysql 5.1.18 connector. simple style request

select * from my_table where column_a in ('aaa','bbb',...) and column b=1;

executed from a java application. the query returns a result set of 25 thousand rows, with 8 columns each. when reading results in a while loop

 while(rs.next()) { MyObject c= new MyObject(); c.setA(rs.getString("A")); c.setB(rs.getString("B")); c.setC(rs.getString("C")); ... } 

the following exception occurs, usually during the first cycles, but never on a single line:

 java.lang.NullPointerException at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5720) at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5570) at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5610) 

I took a look at the source code in ResultSetImpl.java:5720 and I see the following:

 switch (metadata.getSQLType()) 

where is the metadata

 Field metadata = this.fields[internalColumnIndex]; 

and getSQLType is a non-logical receiver returning an int. what is interesting is that the same metadata object is repeatedly called several lines above with other getters and does not exclude any exceptions.

btw, the problem with the query above when starting directly in mysql. the application works in aws.

any ideas how to solve this? thanks.

+4
source share
2 answers

In my experience, this error is the result of a locked table while trying to read / write from the same table. You need to add a pool for each request or some timeout between each operation in MySQL.

Related answer: Getting java.sql.SQLException: operation not allowed after closing ResultSet

0
source

I ran into this problem using Spring Data CrudRepository, getting a stream of results from a MySql database running on AWS RDS with a moderately confusing query.

He would also throw in a non-deterministic line, after about 30 thousand lines.

I solved this problem by annotating the calling method with @Transactional.

Although you are not using JPA, setting up a transaction to access the database may help in your problem.

0
source

Source: https://habr.com/ru/post/1412241/


All Articles