RaF-o-TroniCks

Las Diatribas de un Anónimo de Sevilla, en Segovia.

Browsing Posts in java

File f=new File(urlfile);
if(f.exists()){

byte[] data=getFileBytes(f);
PreparedStatement stmt=conn.prepareStatement(“update campanas3 set media= ? where id=”+id);
stmt.setBlob(1, (Blob)new SerialBlob(data));
stmt.executeUpdate();

}


protected byte[] getFileBytes(File f){

byte[] bytes=null;
try {
FileInputStream fs=new FileInputStream(f);

int contador=0;
byte[] b=new byte[1048576]; //max.1MB
int ch;
Vector tt=new Vector();
while ((ch = fs.read()) != -1) {
b[contador]=(byte)ch;
tt.addElement(new Byte((byte)ch));
contador++;
}

bytes=new byte[tt.size()];
for(int i=0;i
bytes[i]=((Byte)tt.elementAt(i)).byteValue();
}

} catch (Exception e){
e.printStackTrace();
}
return bytes;
}