Java Reference
In-Depth Information
"diameter
real,"+
"mass real,"+
"distance
real,"+
"photo blob)";
stmt.executeUpdate(sql);
sql = "insert into planets values(?, ?, ?, ?,
?)";
try
(PreparedStatement
pstmt
=
con.prepareStatement(sql))
{
for (int i = 0; i < planets.length; i++)
{
pstmt.setString(1, planets[i]);
pstmt.setDouble(2, diameters[i]);
pstmt.setDouble(3, masses[i]);
pstmt.setDouble(4, distances[i]);
Blob blob = con.createBlob();
try (ObjectOutputStream oos =
new
ObjectOut-
putStream(blob.setBinaryStream(1)))
{
ImageIcon
photo
=
new
ImageI-
con(planets[i]+".jpg");
oos.writeObject(photo);
}
catch (IOException ioe)
{
System.err.println("unable
to
write
"+planets[i]+".jpg");
}
pstmt.setBlob(5, blob);
pstmt.executeUpdate();
blob.free(); // Free the blob and release
any held resources.
Search WWH ::




Custom Search