Ho letto la soluzione al link postato ma non riesco a capire alcune parti del codice, qualcuno sa spiegarmelo?
il codice è questo :
codice:
public class JDBCSqliteConn
{
public static void main(String args[]) throws FileNotFoundException, IOException
{
Connection connection = null;
//ResultSet resultSet = null;
PreparedStatement ps = null;
String file = "C:\\Fingerprint\\histoImg_med.png";
Properties prop = new Properties();
int s = 0;
byte[] person_image = null;
File image = new File(file);
FileInputStream fis = new FileInputStream(image);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;)
{
bos.write(buf, 0, readNum);
//no doubt here is 0
/*Writes len bytes from the specified byte array starting at offset
off to this byte array output stream.*/
System.out.println("read " + readNum + " bytes,");
}
} catch (IOException ex) {
System.err.println(ex.getMessage());
}
person_image = bos.toByteArray();
try {
prop.load(new FileInputStream("C:\\dbconfig.properties"));
Class.forName(prop.getProperty("driver"));
connection = DriverManager.getConnection(prop.getProperty("url"));
ps = connection.prepareStatement("INSERT INTO epmc_tbl_test_img (hhld_photo) VALUES (?)");
ps.setBytes(1, person_image);
s = ps.executeUpdate();
if (s > 0)
{
System.out.println("Image Uploaded");
}
ps.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
ps.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
fino alla creazione dell'array da 1024 per il buffer ci sono, non riesco a capire la condizione del ciclo
codice:
try {
for (int readNum; (readNum = fis.read(buf)) != -1;)
{
bos.write(buf, 0, readNum);
//no doubt here is 0
/*Writes len bytes from the specified byte array starting at offset
off to this byte array output stream.*/
System.out.println("read " + readNum + " bytes,");
}
} catch (IOException ex) {
System.err.println(ex.getMessage());
}
cosa rappresenta readNum?
e perchè il secondo parametro di bos.write è 0?