ajanuskevicius
8/22/2016 - 2:12 PM

Java - JDBC - BLOBDataInsert

Java - JDBC - BLOBDataInsert

public class BLOBDataInsert {

	public void insertBLOBState () throws SQLException, IOException {
		
		Connection conn = DB_Util.getConn(DB_Types.MYSQLDB);
		PreparedStatement pst = null;
		Scanner scanner = new Scanner(System.in);
		
		try {
		
		String sql = "update account set file2 = ? where id = ?";
		pst = conn.prepareStatement(sql);
		
		String file2 = "C:/Users/audrius.januskeviciu/Desktop/dept_rates.png";
		File file = new File(file2);
		FileInputStream fis = new FileInputStream(file);
		
		pst.setBinaryStream(1,  fis, fis.available());
		
		System.out.print("Enter Account ID: ");
		pst.setInt(2, scanner.nextInt());
		
		pst.executeUpdate();
		
		System.out.println("Resume Updated Successfully !");
		
		scanner.close();
		pst.close();
		conn.close();
		}
		catch (SQLException e) {
			
			System.out.println("Something wrong - " + e);
		}
	}
}