- 浏览: 177365 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
jiasky:
好像是在练书法。
Oracle Function -
blackangel_can:
这样的代码见得多了。
Javascript Print(*) -
tianhendi:
Apache Solr and Tomcat6 Search engine -
laserdance:
我想问下,你怎么从Tomcat等服务器中把上述文件xml准确定 ...
Java parse XML methods(4) -
cskysnew:
第二种如果去掉synchronized,就不是线程安全的,应该 ...
Singlton ture or not?
Oracle encoding format: UTF8
package com.aaron.dao;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class ConnectCots {
//private final String UID="RCOTRPR1";
//private final String PWD="RCOTRPR1";
private final String UID="RCOTRPR1";
private final String PWD="RCOTRPR1";
private final String DRIVER="oracle.jdbc.driver.OracleDriver";
private final String DBURL = "jdbc:oracle:thin:@192.168.70.54:5201:a3cotr";
private final static String qry="SELECT PAYER_ACC_NO AS EILINE1,PAYER_ACC_NAME AS EILINE2," +
"PAYER_BANK_NAME AS EILINE3,REMARK AS EILINE4 FROM COTS_TAB_DIPS_DETAILS";
public ConnectCots(){
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException e){
System.out.println(e.getMessage());
}
}
public Connection getCon(){
Connection conn=null;
try{
conn=DriverManager.getConnection(DBURL,UID,PWD);
}catch(SQLException e){
System.out.println(e.getMessage());
}
return conn;
}
public void close(Connection con){
if(con!=null){
try{
con.close();
}catch(SQLException e){
System.out.println(e.getMessage());
}
}
}
public ArrayList exeQuery(String sql) throws UnsupportedEncodingException{
ArrayList<String> result=new ArrayList<String>();
Connection connect;
PreparedStatement stmt;
ResultSet rs;
connect=this.getCon();
StringBuffer st=new StringBuffer("");
String filename="d:/aaron.txt";
PrintWriter pw=null;
try {
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF8")),true);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{
stmt=connect.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery(sql);
while(rs.next()){
/*
//aaron
//if(rs.getInt(4)>1 && !rs.isFirst()){
if(rs.getInt(4)>1 && rs.previous()){
if( rs.getString(3).startsWith("BIN") ){
rs.next();
break;
}else{
rs.next();
}
}*/
pw.write(rs.getString("EILINE1")); //get the data from db and write to file by UTF8 format
// st.append(new String(rs.getString("EILINE1").getBytes("UTF8"),"GB2312"));
//st.append("|");
// st.append(new String(rs.getString("EILINE2").getBytes("UTF8"),"GB2312"));
// st.append("|");
st.append(rs.getString("EILINE3"));
st.append("|");
st.append(rs.getString("EILINE4"));
//aaron
//String family=rs.getString(1);
//result.add(family);
}
pw.close();
rs.close();
stmt.close();
}catch(SQLException e){
System.out.println(e.getMessage());
}
this.close(connect);
System.out.println(st.toString());
return result;
}
public void getData(String sql){
Connection connect;
PreparedStatement stmt=null;
ResultSet rs=null;
connect=this.getCon();
try{
stmt=connect.prepareStatement(sql);
rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString("COTS_UID")+"::"+rs.getString("CUSTNUM"));
}
return;
}catch(SQLException e){
System.out.println(e.getMessage());
}
finally{
System.out.println("Enter the finally");
try{
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
this.close(connect);
} catch (Exception ePstmt) {
System.out.println(" Error in Closing Prepared Statement");
}
System.out.println("End the finally");
}
}
public void sbBuffer(){
StringBuffer sb1=new StringBuffer();
sb1.append("hello");
StringBuffer sb2=sb1;
sb2.append(" World");
System.out.println("SB1:"+sb1.toString());
System.out.print("SB2:"+sb2.toString());
}
public static void main(String[] args) {
ConnectCots aaron =new ConnectCots();
//String test="select ACCT_NUM, length(ACCT_NUM) from COTS_TAB_SWP_KR where to_char(COTS_UPD_DT,'YYYYMMDD')='20070626'";
String test="SELECT BENE.COTS_UID COTS_UID,BENE.CUSTNUM CUSTNUM FROM COTS_TAB_BENE_ADVICE BENE WHERE BRANCH=712 AND DELIVERYSTATUS='FAIL'";
String kk="SELECT BENE.COTS_UID COTS_UID,BENE.BRANCH BRANCH,BENE.CUSTNUM CUSTNUM," +
"BENE.TRANSACTIONREF TRANSACTIONREF,BENE.DELIVERYMEDIA DELIVERYMEDIA," +
"BENE.FILENAME FILENAME,BENE.PAYMENTCCY PAYMENTCCY,BENE.PAYMENTAMT PAYMENTAMT," +
"BENE.ACCTNUM ACCTNUM,SITE.EMAILADR EMAILADR " +
"FROM COTS_TAB_BENE_ADVICE BENE,COTS_TAB_BUSINESS_SITE SITE " +
"WHERE BENE.BRANCH=712 AND BENE.DELIVERYSTATUS='FAIL' " +
"AND BENE.BRANCH=SITE.BRANCH " +
"AND BENE.CUSTNUM=SITE.CUSTNUM " +
"AND SITE.SEQUENCENO=1 " +
"ORDER BY BENE.CUSTNUM";
aaron.getData(kk);
}
}
发表评论
-
移动电商
2016-04-19 18:13 551海外旅行购物电商平台-购轻松,是我们从零开发的App应用,欢迎 ... -
Top 10 Books For Advanced Level Java Developers
2013-11-03 21:59 526Top 10 Books For Advanced Level ... -
RESTful
2013-10-28 22:28 677要使API易用、易于接受和足够灵活,应该遵循以下原则: An ... -
Androd app
2012-08-19 21:35 806an android app -
Jenkins-CI
2012-06-30 08:26 796Jenkins for java and .net CI. -
JNLP
2009-04-20 13:26 1162<?xml version="1.0" ... -
Eclipse3.4 + Axis2 Configuration
2009-03-12 19:53 16051) Download the axis2 v1.4 plug ... -
XML configuration for Spring jsf hibernate
2008-07-16 13:51 1122faces-comfig.xml <?xml ver ... -
Final Usage
2008-04-29 21:05 914final在Java中并不常用,然而它却为我们提供了诸如在C语 ... -
Java tips
2008-03-03 21:39 757// 程序1 class Singleton { priv ... -
Java Connect Pool
2008-02-24 19:13 1999import java.io.*; import java.s ... -
Apache Solr and Tomcat6 Search engine
2008-01-04 13:51 2585Today, test the Solr and Tomcat ... -
Java Multiple process (PID)
2007-12-11 11:29 5946Java的多进程运行模式分析 一般我们在java中运行其它类中 ... -
Glassfish V2 And NetBean6
2007-12-05 16:33 1540Dowload Netbean6 from http://ne ... -
Spring用回调HibernateCallBack方法
2007-11-05 15:45 2948Spring用回调HibernateCallBack方法实现持 ... -
Java中的浅复制与深复制
2007-11-05 13:10 1190Java中的浅复制与深复制 分析一下Java中关于浅复制与深复 ... -
Future pattern
2007-11-04 19:54 2160个人理解 Future 模式就是在主线程中当需要进行比较耗时的 ... -
Log4j Configuration (Recitation)
2007-10-14 20:41 2315一、常用输出格式 %c 列出logger名字空间的全称,如加 ... -
JasperReport usage
2007-09-27 22:07 1196jasperreport tools enhance and ... -
Lucene practice
2007-09-19 22:23 10531.simply practice the lucene ap ...
相关推荐
byte[] utf8Bytes = Encoding.UTF8.GetBytes(utf8String); string gb2312String = Encoding.GetEncoding("gb2312").GetString(utf8Bytes); ``` 3. 如果需要读取有BOM的UTF-8文件并转换为其他编码,可以先去除BOM,...
标题"Python-convert2utf将目录下的全部源文件转成UTF8编码"指的是使用Python编写的一个脚本或工具,该工具能够遍历指定目录,检测并转换其中的GB、GBK以及其他非UTF-8编码的文本文件和源代码文件,统一转换为UTF-8...
在Java编程中,UTF-8编码是一个非常常见且广泛使用的字符编码格式,它能支持全球大部分语言的字符表示。然而,UTF-8有一个特殊特性,那就是它可以带有Byte Order Mark(BOM),这是一个特殊的字节序列,用于标识数据...
Learn web scraping and crawling techniques to access unlimited data from any web source in any format. With this practical guide, you’ll learn how to use Python scripts and web APIs to gather and ...
with codecs.open('新文件名', 'w', encoding='utf-8') as utf8_file: utf8_file.write(content) ``` 在上述代码中,`codecs.open()`函数用于打开文件,并指定编码方式。`'r'`表示读取模式,`'w'`表示写入模式。...
with open(filepath, 'w', encoding='utf-8') as f: f.write(content) convert_to_utf8('path/to/your/wpf/project') ``` 这个脚本会遍历指定的目录,并将所有以`.xaml`结尾的文件从UTF-16转换为UTF-8。在实际...
with open('output.txt', 'w', encoding='utf-8') as f_out: f_out.write(content) ``` 在这个过程中,`'input.txt'`文件以GB2312编码读取,内容被解码为Unicode,然后以UTF-8编码写入到`'output.txt'`文件中。 ...
with codecs.open('新文件.utf8', 'w', encoding='utf-8') as f_out: f_out.write(content) ``` 同样,如果要将UTF-8文件转换为GBK,只需将上述代码中的`'gbk'`和`'utf-8'`位置互换即可。 在实际操作中,需要注意...
with open('UTF8_file.txt', 'w', encoding='UTF-8') as outfile: outfile.write(content) # 从UTF-8编码文件转换为GBK编码文件 with open('UTF8_file.txt', 'r', encoding='UTF-8') as infile: content = infile...
displaying spatial-temporal displays with Google Earth, and generating code from descriptions of data structures to read and write data. These topics demonstrate the rich possibilities and ...
byte[] gb2312Bytes = Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("GB2312"), utf8Bytes); return Encoding.GetEncoding("GB2312").GetString(gb2312Bytes); } } ``` 在上述代码中,`ConvertUtf8...
with codecs.open(dest_path, 'w', encoding='utf-8') as dest_file: dest_file.write(content) base_dir = 'TestProject' # 假设TestProject目录下包含需要转换的GBK文件 for filename in os.listdir(base_dir):...
Python Data Structures and Algorithms by Benjamin Baka English | 30 May 2017 | ASIN: B01IF7NLM8 | 310 Pages | AZW3 | 6.63 MB Key Features A step by step guide, which will provide you with a thorough...
本主题将深入探讨如何使用VBA来读取和写入UTF-8编码的文本文件,这对于处理多语言数据或需要跨系统兼容性的项目尤为重要。 1. **UTF-8编码介绍** UTF-8是一种广泛使用的Unicode字符编码,能够表示Unicode字符集中...
UTF-8编码是一种广泛使用的Unicode字符编码方案,它在互联网上尤其常见,因为其兼容性和效率。UTF-8的特点是每个Unicode字符可以被编码为1到4个字节,其中ASCII字符(基本的英文字符)仅需1个字节。这使得UTF-8在...
标题中的"demo_gbk_2_utf8.zip"表明这是一个压缩包文件,它的主要目标是将GBK编码的文件转换为UTF-8编码。在信息技术领域,字符编码是非常关键的一部分,GBK和UTF-8是两种常见的字符编码标准。GBK是基于GB2312扩展的...
read_data_from_PhysioNet.m
STM32学习一:那些MDK5的坑,讲解mdk5在开发stm32的时候一些问题和解决方法