Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $sql = "select link from tabla";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) {
- echo "<img src='".$row["link"]."' >";
- }
- }
- $conn->close();
- public static void main(String[] args) throws Exception, IOException, SQLException {
- Class.forName("org.gjt.mm.mysql.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/databaseName", "usuario", "password");
- String sqlQuery = "insert into tu_tabla(campo_foto) values ( ?)";
- FileInputStream fis = null;
- PreparedStatement ps = null;
- try {
- conn.setAutoCommit(false);
- File archivo = new File("myPhoto.png");
- fis = new FileInputStream(archivo);
- ps = conn.prepareStatement(sqlQuery);
- ps.setBinaryStream(1, fis, (int) file.length());
- ps.executeUpdate();
- conn.commit();
- } finally {
- ps.close();
- fis.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement