import com.atguigu1.util.JDBCUtils;
import org.apache.commons.dbutils.DbUtils;
import org.junit.Test;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class exe {
@Test
public void exe() {
Connection conn = null;
String sql = "insert into customers(name,email,birth,photo)values(?,?,?,?)";
PreparedStatement ps = null;
try {
conn=JDBCUtils.getConnection3();
ps = conn.prepareStatement(sql);
ps.setString(1, "徐海强");
ps.setString(2, "xhq@126.com");
ps.setDate(3, new Date(new java.util.Date().getTime()));
FileInputStream fis = new FileInputStream("xhq.png");
ps.setBlob(4, fis);
ps.execute();
fis.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
DbUtils.closeQuietly(conn,ps,null);
}
}
}