数据库图片导入
2015-11-04 11:07
411 查看
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import com.mysql.jdbc.PreparedStatement; public class Input { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root", "root"); System.out.println("数据库链接成功"); String sql="insert into user value (?,?,?,?)"; PreparedStatement ps=(PreparedStatement) conn.prepareStatement(sql); ps.setInt(1, 1); ps.setString(2, "张三"); ps.setString(3, "123456"); File file=new File("D:/photo/1.jpg");//1 FileInputStream fis=new FileInputStream(file);//2 ps.setBinaryStream(4, fis, (int)file.length()); ps.executeUpdate(); System.out.println("插入数据成功"); if (conn != null) { ps.close(); fis.close(); conn.close(); System.out.println("链接关闭成功"); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
相关文章推荐
- 通过两种方式增加从库――不停止mysql服务
- mysql 查询表死锁 和结束死锁的表步骤
- Mysql千万级别数据优化方案
- oracle数据库psu升级(本实验是将10.2.0.3.12升级到10.2.0.3.15)
- Twemproxy -- 针对MemCached与Redis的代理
- sql 遍历结果集
- SQLserver和oracle中对应的数据类型
- redis 多数据库
- SQLServer基本操作
- excel文件生成本地数据库
- Oracle CHAR,VARCHAR,VARCHAR2,nvarchar类型的区别与使用(转载)
- ORACLE数据库:日期时间函数大全
- 修改mysql的默认存储引擎
- MySQL之explain 的type列 & Extra列
- .NET连接SQL Server的问题处理
- Memcached的管理与监控工具--MemAdmin
- Redis服务器
- MySQL索引原理及慢查询优化
- VS2015下编译 MONGODB 驱动
- 对memcached使用的总结和使用场景