madhawaseeeee

dbstuck

Jul 21st, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. try {
  2.             Connection c1 = null;
  3.  
  4.             c1 = Connec.connection.getCon();
  5.             System.out.println("Opened database successfully");
  6.  
  7.             Statement stmt1 = c1.createStatement();
  8.             String sql1 = "SELECT MAX(id) as mid FROM tags";
  9.             int rowCount = jTable1.getRowCount();
  10.  
  11.             for (int i = 0; i < rowCount; i++) {
  12.                 c1 = Connec.connection.getCon();
  13.                 stmt1 = c1.createStatement();
  14.                 ResultSet rs = stmt1.executeQuery(sql1);
  15.                 rs.next();
  16.                 int mid = rs.getInt("mid");
  17.                 System.out.println("tag id is " + (mid + 1));
  18.                 // stmt1.close();
  19.                 // c1.commit();
  20.                 //c1.close();
  21.                 try {
  22.                     Statement stmt2 = c1.createStatement();
  23.                     String name = (String) jTable1.getValueAt(i, 0);
  24.                     ImageIcon ico = (ImageIcon) jTable1.getValueAt(i, 1);
  25.  
  26.                     String sql = "INSERT INTO tags (name,ico) "
  27.                             + "VALUES ('" + name + "','" + ico + "');";
  28.                     stmt2.executeUpdate(sql);
  29.  
  30.                     stmt2.close();
  31.                     // c1.commit();
  32.                     c1.close();
  33.  
  34.                     Image img = ico.getImage();
  35.                     BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
  36.                     Graphics2D g2 = bi.createGraphics();
  37.                     g2.drawImage(img, 0, 0, null);
  38.                     g2.dispose();
  39.  
  40.                     ImageIO.write(bi, "jpg", new File("C:\\Users\\madhawax\\Desktop\\libry\\img\\tag" + (mid + 1) + ".jpg"));
  41.                 } catch (Exception e) {
  42.                     e.printStackTrace();
  43.                 }
  44.  
  45.             }
  46.         } catch (SQLException ex) {
  47.             Logger.getLogger(Tagform.class.getName()).log(Level.SEVERE, null, ex);
  48.         }
  49.  
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment