SeunMatt / mysql-backup4j

mysql-backup4j is a library for programmatically exporting mysql databases and sending the zipped dump to email, Amazon S3, Google Drive or any other cloud storage of choice
MIT License
124 stars 71 forks source link

Getting java.sql.SQLException when calling export method #9

Closed mavortius closed 4 years ago

mavortius commented 4 years ago

I'm getting java.sql.SQLException: Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY when calling export method. This method seems to finish successfully. I got the email message with attached zip file, but its content has only 'CREATE' statements, there aren't 'INSERT' statements.

SeunMatt commented 4 years ago

Hello, @mavortius please can you provide the following information:

Regards

mavortius commented 4 years ago

Hi @SeunMatt,

This is the stack trace: java.sql.SQLException: Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.result.ResultSetImpl.last(ResultSetImpl.java:1711) at com.smattme.MysqlExportService.getDataInsertStatement(MysqlExportService.java:170) at com.smattme.MysqlExportService.exportToSql(MysqlExportService.java:292) at com.smattme.MysqlExportService.export(MysqlExportService.java:349) at br.com.proinde.databasebackupservice.AutoBackupScheduler.backup(AutoBackupScheduler.java:50) at br.com.proinde.databasebackupservice.AutoBackupScheduler.runBackup(AutoBackupScheduler.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

An interesting thing is that exception happens 50 times consecutively (50 it's the total number of tables and views in my database).

And this is the configuration I'm using for mysql-backup4j:

` Properties props = new Properties(); props.setProperty(MysqlExportService.DB_NAME, "my_db"); props.setProperty(MysqlExportService.DB_USERNAME, "root"); props.setProperty(MysqlExportService.DB_PASSWORD, "root_password");

props.setProperty(MysqlExportService.EMAIL_HOST, "mail_host");
props.setProperty(MysqlExportService.EMAIL_PORT, "587");
props.setProperty(MysqlExportService.EMAIL_USERNAME, "mail_user");
props.setProperty(MysqlExportService.EMAIL_PASSWORD, "password");
props.setProperty(MysqlExportService.EMAIL_FROM, "user@mail.com");
props.setProperty(MysqlExportService.EMAIL_TO, "to_user@mail.com");

props.setProperty(MysqlExportService.TEMP_DIR, new File("external").getPath());
MysqlExportService mysqlExportService = new MysqlExportService(props);
mysqlExportService.export();
mysqlExportService.clearTempFiles(false);

`

It's not so complex, just using as it is in blog's library. I think that exception happens when the library tries to write INSERT instructions to sql script file.

mavortius commented 4 years ago

The size of the sql script generated file has only 6KB, this size isn't right because the sql script file generated manually by mysqldump for my database is up to 35MB. As I said before, the content of that "wrong" file has only CREATE instructions not INSERT for data, while the generated sql script file by mysqldump has INSERT instructions too.

pulkitsharva commented 4 years ago

hi, @SeunMatt I am also facing the same issue. The SQL file generated by the library has only create table instructions and it is missing insert data instructions

SeunMatt commented 4 years ago

Hello @pulkitsharva, I will look into it, hopefully, this weekend. Do check back by then.

Thanks

SeunMatt commented 4 years ago

Hello @pulkitsharva and @mavortius this issue has been fixed in version 1.2.0

mavortius commented 4 years ago

Hello @pulkitsharva and @mavortius this issue has been fixed in version 1.2.0

Thanks for your work!