Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. $sql = "select link from tabla";
  2. $result = $conn->query($sql);
  3.  
  4. if ($result->num_rows > 0) {
  5.  
  6. while($row = $result->fetch_assoc()) {
  7. echo "<img src='".$row["link"]."' >";
  8. }
  9. }
  10. $conn->close();
  11.  
  12. public static void main(String[] args) throws Exception, IOException, SQLException {
  13. Class.forName("org.gjt.mm.mysql.Driver");
  14. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/databaseName", "usuario", "password");
  15. String sqlQuery = "insert into tu_tabla(campo_foto) values ( ?)";
  16.  
  17. FileInputStream fis = null;
  18. PreparedStatement ps = null;
  19. try {
  20. conn.setAutoCommit(false);
  21. File archivo = new File("myPhoto.png");
  22. fis = new FileInputStream(archivo);
  23. ps = conn.prepareStatement(sqlQuery);
  24. ps.setBinaryStream(1, fis, (int) file.length());
  25. ps.executeUpdate();
  26. conn.commit();
  27. } finally {
  28. ps.close();
  29. fis.close();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement