Implemented Producer-Consumer
pattern . The Producer
class produces images and Consumer
writes them to the database . If the Consumer
class replaces the code (which writes to the database ) with the code that will write these images to disk, then everything works. If you check everything line by line, then preparedStatement.executeUpdate();
it just skips and immediately goes into the Exception
block. No mistake, nothing.
Here the record is realized:
String id_tile; int zoomLvl; int x; int y; byte[] imageInByte; String id_photo; DataLoader dat = new DataLoader(); private boolean available = false; public synchronized void get() throws IOException, SQLException { while (available == false) { try { wait(); } catch (InterruptedException e) { } } // метод, который записывает в БД (должен записывать) dat.insertToTiles(id_tile, zoomLvl, x, y, imageInByte, id_photo); available = false; notifyAll(); } public synchronized void put(String id_tile, int zoomLvl, int i, int j, byte[] imageInByte, String id_photo) throws IOException { while (available == true) { try { wait(); } catch (InterruptedException e) { } } this.id_tile = id_tile; this.zoomLvl = zoomLvl; this.x = i; this.y = j; this.id_photo = id_photo; this.imageInByte = imageInByte; available = true; notifyAll(); }
Values in parameters checked, all are filled, no null
equal.
Here is the write method itself:
public void insertToTiles(String id_tile, int zoom, int x, int y, byte[] image, String id_photo) throws SQLException { Connection conn = SingletonDBConnection.getConnection(); PreparedStatement pstmt = null; try { String query = "insert into tiles(id_tile, zoom, x, y, image, id_photo) "+ "values(?,?,?,?,?,?)"; pstmt = conn.prepareStatement(query); pstmt.setString(1, id_tile); pstmt.setInt(2, zoom); pstmt.setInt(3, x); pstmt.setInt(4, y); pstmt.setBytes(5, image); pstmt.setString(6, id_photo); pstmt.executeQuery(); } catch (Exception e) { System.out.println("Error !"); } }
Added e.stacktrace
and gave the following error:
org.postgresql.util.PSQLException: ERROR: the current transaction is aborted; QueryExecutorImpl.processResults (QueryExecutorImpl.java:1998) at org.ht; isch.jdbc2.AbstractJdbc2Statement.executeWithFlags (AbstractJdbcS2Statement.java:420) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery (AbstractJdbc2Statement.jbc of ischrah of isch ischrechtQuery (aboutJdbc2Statement.jbc) ist of isch isch ischt (ischra). 26) at Consumer.run (Consumer.java:21) at java.lang.Thread.run (Thread.java:745)
e.printStackTrace()
. - Tagir Valeevcatch(Exception e) {
adde.printStackTrace();
and run again. Add the very first error message to the question that will be issued (along with the class names, line numbers, etc.) - Tagir Valeev