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

java操作oracle数据库

 package com.chinacache.boss.queryservice.service.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.chinacache.boss.queryservice.exception.BusinessException;
import oracle.sql.ArrayDescriptor;
public class Main {
public static void main(String[] args) throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
java.sql.Array sqlArray = null;
conn = getOracleConnection();
// For oracle you need an array descriptor specifying
// the type of the array and a connection to the database
// the first parameter must match with the SQL ARRAY type created
ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor(
"CHAR_ARRAY", conn);// CREATE OR REPLACE TYPE CHAR_ARRAY AS table OF VARCHAR2(255)
// then obtain an Array filled with the content below
String[] content = { "5137", "V2", "V3", "V4" };
sqlArray = new oracle.sql.ARRAY(arrayDescriptor, conn, content);
pstmt = conn.prepareStatement(""
+ "select * "
+ "from bandwith_area_test t where t.channel_id in (select * from the (select cast(? as CHAR_ARRAY) from dual)) and t.area_id = ?" + "and t.day >= ? and t.day <= ? order by t.day");
Date start = null;
Date end = null;

try {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm");
start = df.parse("200907011000");
end = df.parse("200907012000");
} catch (ParseException e) {
e.printStackTrace();
throw new BusinessException(e.getMessage());
}

pstmt.setArray(1, sqlArray);
pstmt.setString(2, "9050");
pstmt.setDate(3, new java.sql.Date(start.getTime()));
pstmt.setDate(4, new java.sql.Date(end.getTime()));
int rowCount = pstmt.executeUpdate();
System.out.println("rowCount=" + rowCount);
System.out.println("--Demo_PreparedStatement_SetArray end--");
pstmt.close(


相关文档:

java入门

 Java学习从入门到精通 
一、 JDK (Java Development Kit) 
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......

JAVA静态方法的同步问题~~~~~~~~~~~~~

一直被同步搞得晕头转向,今天遇到了要写静态方法,总担心会不会有同步问题,结果看了以下一席话,豁然开朗~~
Every method of java will have a stack, and every invokation on that
method will have it's own 'stack frame'. So the locale data of one
method invokation will not affect others.
Please do not c ......

从Java应用程序动态生成PDF文件

 http://hi.baidu.com/skeryl/blog/item/d9b74e081e1d423ae92488ac.html
如果应用程序需要动态生成 PDF 文档,则需要 iText 库。开放源码的 iText 库使 PDF 文档的创建能够在瞬间完成。本文介绍了 iText 并提供了使用它从 Java ? 技术应用程序生成 PDF 文档的由浅入深的指南。我们创建了一个示例应用程序以更好地理解 ......

Java Filter 过滤器的使用

1、建立一个Servlet并且实现Filter接口
该类需要实现Filter接口中的init()   doFilter()    destory()方法
其中init()方法自动在项目启动的时候加载,doFilter()在调用xml配置的路径是加载,destory()方法在退出项目的时候进行。
 
public class TestFilter implements Filter{
  ......

java获得实效时间,当前时间推迟1个月的时间

     /**
     * 获得实效时间,当前时间推迟1个月的时间<br>
     *
     * @return
     */
    private String getInvalidationTime() {
        String invalidationTime ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号