Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- Connection c1 = null;
- c1 = Connec.connection.getCon();
- System.out.println("Opened database successfully");
- Statement stmt1 = c1.createStatement();
- String sql1 = "SELECT MAX(id) as mid FROM tags";
- int rowCount = jTable1.getRowCount();
- for (int i = 0; i < rowCount; i++) {
- c1 = Connec.connection.getCon();
- stmt1 = c1.createStatement();
- ResultSet rs = stmt1.executeQuery(sql1);
- rs.next();
- int mid = rs.getInt("mid");
- System.out.println("tag id is " + (mid + 1));
- // stmt1.close();
- // c1.commit();
- //c1.close();
- try {
- Statement stmt2 = c1.createStatement();
- String name = (String) jTable1.getValueAt(i, 0);
- ImageIcon ico = (ImageIcon) jTable1.getValueAt(i, 1);
- String sql = "INSERT INTO tags (name,ico) "
- + "VALUES ('" + name + "','" + ico + "');";
- stmt2.executeUpdate(sql);
- stmt2.close();
- // c1.commit();
- c1.close();
- Image img = ico.getImage();
- BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
- Graphics2D g2 = bi.createGraphics();
- g2.drawImage(img, 0, 0, null);
- g2.dispose();
- ImageIO.write(bi, "jpg", new File("C:\\Users\\madhawax\\Desktop\\libry\\img\\tag" + (mid + 1) + ".jpg"));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } catch (SQLException ex) {
- Logger.getLogger(Tagform.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment