1 Mysql表结构
2 写入数据到mysql中的photo的mediumblob字段中
(注意:由于是演示代码,里面的异常处理,和关闭资源都做了最简单的方式,开发中需要进行相应处理。)
(1)连接数据库代码
public static Connection getConnection() throws Exception {
Connection conn = null;
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("jdbc.properties");
Properties properties = new Properties();
properties.load(is);
String user = properties.getProperty("user");
String password = properties.getProperty("password");
String url = properties.getProperty("url");
String driver = properties.getProperty("driverClass");
Class.for