易截截图软件、单文件、免安装、纯绿色、仅160KB

用JAVA写入和读取MYSQL的图片的实例

主要的程序:
package greeds.jdbc.sample;
import greeds.jdbc.util.JDBCUtil;
import java.io.*;
import java.sql.*;
public class MySQLBlobSample {
 public static void main(String[] args) throws Exception {
  // 写入数据库
  /*
   *
   * Connection conn = null; PreparedStatement pstm = null;
   *
   * try { String filepath = "D:\\strahovski-ep201-011.jpg"; File file =
   * new File(filepath); FileInputStream fin = new FileInputStream(file);
   * conn = JDBCUtil.getConnection();
   *
   * String sql = "insert into Dish(id,photo) values(?,?)"; pstm =
   * conn.prepareStatement(sql); pstm.setInt(1, 3);
   * pstm.setBinaryStream(2, fin,(int)file.length());
   *
   * int r = pstm.executeUpdate(); System.out.println("INSERT"+r+"ROW");
   *
   * fin.close();
   *
   *
   * } catch (FileNotFoundException e) { e.printStackTrace(); } finally{
   * //JDBCUtil.release(null, pstm, conn); }
   */
  // 从数据库读取文件
  Connection conn = null;
  Statement stm = null;
  ResultSet rs = null;
  try {
   conn = JDBCUtil.getConnection();
   stm = conn.createStatement();
   String sql = "select * from Dish where id=1";
   rs = stm.executeQuery(sql);
   rs.next();
   Blob blob = rs.getBlob("photo");
   FileOutputStream out = new FileOutputStream(new File("E:/my.jpg"));
   InputStream in = blob.getBinaryStream();
   int i;
   while ((i = in.read()) != -1) {
    out.write(i);
   }
   in.close();
   out.close();
  } catch (Exception e) {
   e.pr


相关文档:

MySQL给用户名添密码的五种方法(转载)

1.通过修改MYSQL数据库中MYSQL库的USER表 
       就用普通的UPDATE、INSERT语句就可以 
use mysql 
update user set Password=password('newpassword') where User='root'; 
flush privileges; 
(这个亲自实验过,可以执行!)
2.在命令行中使用如下命令 
&nbs ......

使用Jena将本体存入MySQL——文档和例子


 iMarine http://iMarine.blog.163.com
注明:本文档参考Jena 2.5文档,使用Jena 2.5 API和MySQL 5.0.4-beta-nt数据库。MySQL驱动包使用的是mysql-connector-java-3.1.10-bin.jar。
1 Jena的数据库接口
Jena提供了将RDF数据存入关系数据库的接口,Model、Resource、Query等接口可以用于访问和维护数据库里的RDF数 ......

在JAVA 源程序中编写SQL语句时使用ORACLE 绑定变量

在JAVA中的SQL 语句的编写方面,没有使用ORACLE 绑定变量,很大程度上降低了数据库的性能,表现在两个方面:
 
1、SQL语句硬分析(Hard Parse)太多,严重消耗CPU资源,延长了SQL语句总的执行时间
SQL语句的执行过程分几个步骤:语法检查、分析、执行、返回结果。其中分析又分为硬分析(Hard Parse)和软分析(Soft Pars ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号