易截截图软件、单文件、免安装、纯绿色、仅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汉字字符串按拼音排序

目标:实现一个汉字字符串按汉语拼音字典顺序排序。
原理:在windows环境的gbk字符集里,汉字是按汉语拼音字典顺序编码的,如“础”是B4A1,“储”是B4A2。这里有个问题就像上面的储和础这样的同音字只能遵照编码的顺序了,另外多音字也得遵照编码顺序。设计思路是先拆分汉字字符串为字符数组,获得每 ......

Java代码生成和解析xls文件

使用poi来生成xls文件:引用的包poi-3.2.final.jar;
要了解的类HSSFWorkbook,HSSFSheet,HSSFRow,HSSFCell
HSSFWorkbook workbook=new HSSFWorkbook();得到一个Excel文件的引用
HSSFSheet sheet=workbook.createSheet();得到一个sheet,还有HSSFSheet sheet=workbook.createSheet("sheet1");方法可以设置Sheet的名称。
然 ......

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获得实效时间,当前时间推迟1个月的时间

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