Quantcast
Channel: BTSoru.com - Bilisim ve Yazilim Teknolojileri Soru/Cevap Platformu - latest questions
Viewing all articles
Browse latest Browse all 4270

Javada resim(image) database -e nasil yuklenir?

$
0
0

Salam Aleykum. MySql e resim download etmek istiyorm online test projesi icin. Internetden boyle bir kod buldum fakat calishmiyor. Myphoto.png -ni nerden eklemesi gerekir.

import java.io.File;

import java.io.FileInputStream; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException;

public class NewClass {

public static void main(String[] args) throws Exception, IOException, SQLException {
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/db.exam", "root", "fabio");
    String INSERT_PICTURE = "insert into questions(id, name, photo) values (?, ?, ?)";

    FileInputStream fis = null;
    PreparedStatement ps = null;
    try {
        conn.setAutoCommit(false);
        File file = new File("myPhoto.png");
        fis = new FileInputStream(file);
        ps = conn.prepareStatement(INSERT_PICTURE);
        ps.setString(1, "001");
        ps.setString(2, "name");
        ps.setBinaryStream(3, fis, (int) file.length());
        ps.executeUpdate();
        conn.commit();
    } finally {
        ps.close();
        fis.close();
    }
}

}


Viewing all articles
Browse latest Browse all 4270

Trending Articles


Foxtrot Six Türkçe Dublaj izle (2020)


Kara Noel Türkçe Dublaj izle (2019)


mülk suresi okumanın fazileti


Ahiyyen ya hayy şerahiyyen ya kayyum


Göz perdesi


...Manevi Güç İçin...


ervahı tayyibeyi davet etmek için yasin suresi tertibi


Kalp gözünü açmak için kolay yollar


Hadi Gidelim Türkçe dublaj izle (2020)


Şekilli süslü hazır floodlar