Bug #115781 stored procedure with cursor reading (useCursorFetch=true) hang
Description:
When using MySQL JDBC to execute a stored procedure with cursor reading (useCursorFetch=true, fetchsize>0), if there is an unexpected exception within the stored procedure, the JDBC will not throw an error and instead hang indefinitely. However, in normal mode and streaming mode, the exceptions in the stored procedure are timely thrown (assuming there is no specified exception-handling syntax within the stored procedure).
How to repeat:
java.io.File;lportmport java.util.ArrayList;mport java.util.Calendar;mport java.util.List;mport java.util.Date;
mport java.sql.*;mport java.text .SimpleDateFormat;
ublic class Test [
public static void main(String args[]) throws ExceptionfSimpleDateFormat formater = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss .SSs");String jdbc_type = args[o];String ip = args[1];String port = args[2];String user = args[3];String pass = args[4];String db = args[5];
if(jdbc_type.equals("57"))[Class.forName("com.mysql.jdbc.Driver"); else {Class.forName("com.mysql.cj.jdbc.Driver");
System.out ,printIn(formater .format(new Date(System.currentTimeMillis())) + " jdbc_type: "+jdbc type)!
String url = "jdbc:mysql://" + ip +“:" + port +“/" + db +?useSSL=false&useCursorFetch=true&useServerPrepStmts=true";System.out.printIn(formater,format(new DateSystem,currentTimeMillis())) + " url: " + url);
Connection conn1 = null;PreparedStatement stmt = null ;
ResultSet rs = null;
try lSystem.out.println(formater,format(new Date(System,currentTimeMillis())) + " connecting ...");conn1 = DriverManager .getConnection(url, user, pass);System.out,println(formater,format(new Date(System. currentTimeMillis())) + " connected")stmt = conn1.prepareStatement("select 1 fromdual where 1=(select1 as a union all select 2)")stmt.setFetchSize(100);System.err.println(formater.format(new Date(System. currentTimeMillis())) + " query ...");rs = stmt .executeQuery();] catch (Exception e)
e.printStackTrace();finally (if(null!=rs){try{rs.close();}catch (Exception ignore) [}
System.err.printIn(formater .format(new Date(System.currentTimeMillis()))+
+ e.getMessage());
if(null!=stmt){try{stmt.close();}catch (Exception ignore)[}
if(null!=conn1){try{conn1.close();}catch (Exception ignore)
Suggested fix:
Report errors in time
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: When using MySQL JDBC to execute a stored procedure with cursor reading (useCursorFetch=true, fetchsize>0), if there is an unexpected exception within the stored procedure, the JDBC will not throw an error and instead hang indefinitely. However, in normal mode and streaming mode, the exceptions in the stored procedure are timely thrown (assuming there is no specified exception-handling syntax within the stored procedure). How to repeat: java.io.File;lportmport java.util.ArrayList;mport java.util.Calendar;mport java.util.List;mport java.util.Date; mport java.sql.*;mport java.text .SimpleDateFormat; ublic class Test [ public static void main(String args[]) throws ExceptionfSimpleDateFormat formater = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss .SSs");String jdbc_type = args[o];String ip = args[1];String port = args[2];String user = args[3];String pass = args[4];String db = args[5]; if(jdbc_type.equals("57"))[Class.forName("com.mysql.jdbc.Driver"); else {Class.forName("com.mysql.cj.jdbc.Driver"); System.out ,printIn(formater .format(new Date(System.currentTimeMillis())) + " jdbc_type: "+jdbc type)! String url = "jdbc:mysql://" + ip +“:" + port +“/" + db +?useSSL=false&useCursorFetch=true&useServerPrepStmts=true";System.out.printIn(formater,format(new DateSystem,currentTimeMillis())) + " url: " + url); Connection conn1 = null;PreparedStatement stmt = null ; ResultSet rs = null; try lSystem.out.println(formater,format(new Date(System,currentTimeMillis())) + " connecting ...");conn1 = DriverManager .getConnection(url, user, pass);System.out,println(formater,format(new Date(System. currentTimeMillis())) + " connected")stmt = conn1.prepareStatement("select 1 fromdual where 1=(select1 as a union all select 2)")stmt.setFetchSize(100);System.err.println(formater.format(new Date(System. currentTimeMillis())) + " query ...");rs = stmt .executeQuery();] catch (Exception e) e.printStackTrace();finally (if(null!=rs){try{rs.close();}catch (Exception ignore) [} System.err.printIn(formater .format(new Date(System.currentTimeMillis()))+ + e.getMessage()); if(null!=stmt){try{stmt.close();}catch (Exception ignore)[} if(null!=conn1){try{conn1.close();}catch (Exception ignore) Suggested fix: Report errors in time