Java程序连接DB2
1、把DB2安装目录下的db2java.zip导入到项目的外部类,如我是把D:\Program Files\IBM\SQLLIB\java下的db2java.zip导入的。
2、在程序中建立连接:
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
String url="jdbc:db2:mydb"; //不必指定主机名和端口号,指定了反而会出错
String user="*****";
String password="******";
conn=DriverManager.getConnection(url,user,password);
3、接下去便可以直接进行查询了:
st=(Statement) conn.createStatement();
rs=st.executeQuery(query);
相关文档:
压缩文件代码:
import java.io.*;
import java.util.zip.*;//ZipOutputStream这个流在这里
public class ZipOutputStreamTest
{
public static void main(String[] args) throws Exception
{
File f = new File("C:\\aaa.csv");
FileInputStream fis = new FileInputStream(f);
B ......
http://babyjoycry.javaeye.com/blog/587527
1. import info.monitorenter.cpdetector.io.CodepageDetectorProxy;
2. import info.monitorenter.cpdetector.io.HTMLCodepageDetector;
3. import info.monitorenter.cpdetector.io.JChardetFacade;
4.
5. import java.io.BufferedReader;
......
公司Vac方法过滤器使用到反射机制,读取xml配置文件过滤用户访问的方法名是否合法。
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRe ......
这个谜题之所以被称为长整除是因为它所涉及的程序是有关两个long型数值整除的。被除数表示的是一天里的微秒数;而除数表示的是一天里的毫秒数。这个程序会打印出什么呢?
public class LongDivision{
public static void main(String args[]){
final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000;
final lo ......
下面的程序使用了复合的异或赋值操作符,它所展示的技术是一种编程习俗。那么它会打印出什么呢?
public class CleverSwap{
public static void main(String[] args){
int x = 1984; // (0x7c0)
int y = 2001; // (0x7d1)
x^= y^= x^= y;
System.out.println("x= " + x + "; y= " + y);
}
}
就像其名称 ......