Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/wp_dashort", "dashort",
"gt9wkk6r1TPnkgrY");
PreparedStatement ps = null;
ps = connection.prepareStatement(mark_complete);
System.out.println("dateset");
dateof = dateof + " 00:00";
// ps.setString(1, dateof);
connection.createStatement();
ResultSet rs = ps.executeQuery();
Sheet sheet = workbook.createSheet("Security_Completions");
org.apache.poi.ss.usermodel.Row rowhead = sheet.createRow((short) 0);
System.out.println("Sheet created");
rowhead.createCell((short) 0).setCellValue("Column 1");
rowhead.createCell((short) 1).setCellValue("Column 2");
int size = 0;
rs.last();
size = rs.getRow();
rs.beforeFirst();
System.out.println("Number of records = " + size);
// Running thru the ResultSet
int index = 0;
int r = 0;
rs.next();
while (r < size) {
index = index + 1;
Row row = sheet.createRow((short) index);
for (int i = 0; i < 1; ++i) {
String value = rs.getString(1);
row.createCell(i).setCellValue(value);
row.createCell(1).setCellValue(StringUtils.left((rs.getString(2)), 16));
rs.next();
}
++r;
}
So this code worked fine just last week. This week I have been forced to connect to the MySQL server using an SSH tunnel session.
I get the SQLException "Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY" It seems that when I get the last row and then try to iterate through to write a spreadsheet, the error is thrown.