Connection con = null;
PreparedStatement pstmt = null;
ResultSet rst = null;
int i = 0;
String sql = "select * from person";
InputStream is = null;
OutputStream os = null;
try { long beginTime = System.currentTimeMillis();
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:aolei", "aolei", "aolei");
pstmt = con.prepareStatement(sql);
rst = pstmt.executeQuery();
while (rst.next()) {
BLOB blob = (BLOB) rst.getBlob(4);
is = blob.getBinaryStream();
File file = new File("d:/out/output"+i+".txt"); try {
os = new FileOutputStream(file);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
byte[] b = new byte[1024];
int len = 0;
try {
while ((len = is.read(b)) != -1) {
os.write(b, 0, len);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} try {
os.flush();
is.close();
} catch (Exception e) {
// TODO: handle exception
} i++;
}
// System.out.println("length"+a);
System.out.println("记录数" + i + "个");
long endTime = System.currentTimeMillis();
float sumTime = (float) (endTime - beginTime) / 1000;
System.out.println(sumTime + "秒");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("没找到驱动类");
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rst != null) {
rst.close();
}
if (pstmt != null) {
pstmt.close();
}
if (con != null) {
con.close();
}
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
} catch (SQLException s) {
s.printStackTrace();
}
}
请问byte[] b = new byte[1024];
int len = 0;
try {
while ((len = is.read(b)) != -1) {
os.write(b, 0, len);
}
}
b的范围,是越大存入影片速度越快吗
PreparedStatement pstmt = null;
ResultSet rst = null;
int i = 0;
String sql = "select * from person";
InputStream is = null;
OutputStream os = null;
try { long beginTime = System.currentTimeMillis();
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:aolei", "aolei", "aolei");
pstmt = con.prepareStatement(sql);
rst = pstmt.executeQuery();
while (rst.next()) {
BLOB blob = (BLOB) rst.getBlob(4);
is = blob.getBinaryStream();
File file = new File("d:/out/output"+i+".txt"); try {
os = new FileOutputStream(file);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
byte[] b = new byte[1024];
int len = 0;
try {
while ((len = is.read(b)) != -1) {
os.write(b, 0, len);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} try {
os.flush();
is.close();
} catch (Exception e) {
// TODO: handle exception
} i++;
}
// System.out.println("length"+a);
System.out.println("记录数" + i + "个");
long endTime = System.currentTimeMillis();
float sumTime = (float) (endTime - beginTime) / 1000;
System.out.println(sumTime + "秒");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("没找到驱动类");
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rst != null) {
rst.close();
}
if (pstmt != null) {
pstmt.close();
}
if (con != null) {
con.close();
}
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
} catch (SQLException s) {
s.printStackTrace();
}
}
请问byte[] b = new byte[1024];
int len = 0;
try {
while ((len = is.read(b)) != -1) {
os.write(b, 0, len);
}
}
b的范围,是越大存入影片速度越快吗
解决方案 »
- Java中用字符串作为变量名来反射声明变量,能实现吗
- oracle调用JAVA存储过程出错
- 如何查询数据库中 yyyy-mm-dd 提前 5 天的数据?
- 请教:JAVA中JTable中自适应或自定义宽度和与,以及数据库导操作的几个疑问
- 请教高手:网页占用80端口,jsp程序只能用8088端口,客户无法访问如何解决
- 网页的字体加亮功能如何实现?
- 急!关于日期问题
- java中的接口能new吗?我可以new一个runnable吗?
- 就学习sun one ce和jbuilder 8 使用版的初步体会。
- 请教高手:有没有人见过这个异常,关于数据库访问。送分!
- JFrame如何透明边框?如果不可以,那Java中有什么类可以?
- ProgressBar??
只要够用就OK了.一定程度了,是没有什么性能上提升了.
个人感觉
因为 b 占用的内存 文件占用硬盘空间
如果 b太大 就会导致内存不足速度反而慢.
如果太小 分割的次数就会太多.也不合理.所以要根据你的 文件和内存 来选择一个合适的值.