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

java如何里将文件存到数据库中

public class InsertBlobData {
Connection con = null;
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
InsertBlobData data = new InsertBlobData();
data.insertBlogInfo("002jpg", "sdsdfdf", "2007-02-12", "002.jpg");
}
public void insertBlogInfo(String jmzh, String xm, String smsj,
String fileName) throws Exception {
// try {
con = ConnectionPoliceFactory.getFactory().getConnection();
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// 处理事务
boolean defaultCommit = con.getAutoCommit();
con.setAutoCommit(false);
Statement st = con.createStatement();
// 插入一个空对象
st.executeUpdate("insert into ksren_txxx(jmzh,xm,smsj,txsj) values('"
+ jmzh + "','" + xm + "',to_date('" + smsj
+ "','yyyy-mm-dd'),empty_blob())");
// 用for update方式锁定数据行
ResultSet rs = st
.executeQuery("select txsj from ksren_txxx where jmzh='"
+ jmzh + "' and xm='" + xm + "' for update");
if (rs.next()) {
// 得到java.sql.Blob对象,然后Cast为oracle.sql.BLOB
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
// 到数据库的输出流
OutputStream outStream = blob.getBinaryOutputStream();
// 这里用一个文件模拟输入流
InputStream fin = new FileInputStream(new File(fileName));
// 将输入流写到输出流
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ((len = fin.read(b)) != -1) {
outStream.write(b, 0, len);
// blob.putBytes(1,b);
}
// 依次关闭(注意顺序)
fin.close();
outStream.flush();
outStream.close();
con.commit();
/* 恢复原提交状态 */
con.setAutoCommit(defaultCommit);
con.close();
}
}
}


相关文档:

Java多线程的相关机制

一 线程的基本概念
线程是一个程序内部的顺序控制流.一个进程相当于一个任务,一个线程相当于一个任务中的一条执行路径.;多进程:在操作系统中能同时运行多个任务(程序);多线程:在同一个应用程序中有多个顺序流同时执行;Java的线程是通过java.lang.Thread类来实现的;JVM启动时会有一个由主方法(public static void main( ......

Java线程知识深入解析(1)

一般来说,我们把正在计算机中执行的程序叫做"进程"(Process) ,而不将其称为程序(Program)。所谓"线程"(Thread),是"进程"中某个单一顺序的控制流。新兴的操作系统,如Mac,Windows NT,Windows 95等,大多采用多线程的概念,把线 程视为基本执行单位。线程也是Java中的相当重要的组成部分之一。
甚至最简单的Applet也是由多个线 ......

JAVA 爬网页用 例如:http://www.126.com

/*
Function name: myGetHttpFile2
Description: 爬网页用
Input: URL 例如:http://www.126.com
Output: 字符串,网页的HTML
*/
public String myGetHttpFile2(String url){
String authentication=null;
ArrayList al=new ArrayList();
String PageURL = url;
......

java 缩略图 实现

import  java.awt.image. * ;
import  com.sun.image.codec.jpeg. * ;   
 public class poiReadDoc {
 Image img = null;
 int width = 0,height =0;
 String destFile = "";
 public void readImg(String fileName) throws IOException{
  File _fil ......

关于java的++和

public class JavaPlus {

public static void main(String[] args) {
int x = 5;
x++;// x = x + 1;//后加加
System.out.println(x);
x--;// x = x - 1;//后减减
System.out.println(x);
++x;// x = x + 1;//前加加
Sys ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号