Java根据Url下载图片
2020-11-24 13:08
标签:java url 图片
JdbcUtil类代码如下: Java根据Url下载图片 标签:java url 图片 原文地址:http://blog.csdn.net/ro_wsy/article/details/24673333package com.ronniewang.downloadpicture;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import com.ronniewang.utilities.JdbcUtil;
public class DownloadPicture {
public static void main(String[] args) {
DownloadPicture downloadPicture = new DownloadPicture();
ArrayList
package com.ronniewang.utilities;
import java.sql.*;
import javax.sql.*;
/**
* 连接mysql数据库的工具类,用来作为DownloadPicture进行数据库连接的辅助类
* @author Administrator
*
*/
public final class JdbcUtil {
//下列配置换成相应内容即可
private static String url = "jdbc:mysql://localhost:3306/test";
private static String user = "root";
private static String password = "123456";
private JdbcUtil() { }
static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new ExceptionInInitializerError(e);
}
}
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection(url, user, password);
}
public static void free(ResultSet rs, Statement st, Connection conn) {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
}
数据库测试表字段为id和url两列