mysql插入图片数据
来源:互联网 发布:java collection遍历 编辑:程序博客网 时间:2024/05/24 06:23
import java.sql.*; import java.util.Scanner;import java.io.*; public class mysql插入图片 { private static final File File = null; private static String String; public static Connection getConn() { Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/xinxi", "root", "123456"); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } public static void add( String fromFileName, String toFileName) { Connection conn = getConn();
String sql = <span style="font-family: simsun;">"insert into image( id , image) values(?,?)"</span><span style="font-family: simsun;">;</span> PreparedStatement ps; try { ps = conn.prepareStatement(sql); ps.setString(1, "tupian"); File file1=new File("D:\\test.jpg"); InputStream in; in = new BufferedInputStream(new FileInputStream(file1)); ps.setBinaryStream(2, in, (int) file1.length()); int count = 0; count = ps.executeUpdate(); if(count==1) { System.out.println("success"); }else { System.out.println("failed"); } in.close(); ps.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); }catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
0 0
- mysql插入图片数据
- 向mysql中插入数据(时间,图片)
- mysql插入图片
- Mysql插入图片
- 优化MySQL插入数据
- php插入mysql数据
- MySql循环插入数据
- mysql海量数据插入
- mysql批量插入数据
- MySQL插入数据
- sae mysql 插入数据
- mysql循环插入数据
- MySql循环插入数据
- mysql 循环插入数据
- Mysql插入数据错误
- mysql 插入数据加快
- mysql 插入数据问题
- Mysql插入数据乱码
- 桥梁模式
- Did you forget to add '#include "stdafx.h"' to your source?
- JAVA正则表达式 Pattern和Matcher
- Class.getResource与Class.getClassLoader.getResource
- iTunes Store operation failed 解决方案
- mysql插入图片数据
- c#备注常识
- cmd下编译、运行java工程(二)
- 关于数据库(SQL)中Empty String即('') 与 Null的区别?
- IOS/MAC中使用Thrift框架
- ARM中MRS汇编指令
- WinCE: OSDesign Configuration(下载image到板子上)
- Android View坐标getLeft, getRight, getTop, getBottom
- Servlet 获取 Spring 中的对象