I understand how to fetch a URL text page and loop over the results
URL url = new URL(this.url);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = reader.readLine()) != null) {
....
How would I do this to fetch an image and store it as a Blob?
Just get it straight as
InputStreamand usePreparedStatement#setBinaryStream()to store it. It’s binary data, not character data, so aReaderwould only messup things, you don’t want to have that.In a nutshell:
A
PreparedStatementis really useful. It not only saves you from SQL injections, but it also eases setting fullworthy Java objects likeInputStreamin a SQL statement. You can learn more aboutPreparedStatementat the JDBC tutorial.