Java连接DB2数据库

package com.yc.ycportal.ge.util;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DB2Connect {

public static Log log = LogFactory.getLog(DB2Connect.class);
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String uri = "jdbc:db2:/192.168.0.66/ycportal";
String userName = "db2admin";
String passWord = "admin";

public DB2Connect(){
   try {
    Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").isInterface();
   } catch (ClassNotFoundException e) {
    log.error(e.getMessage());
   }
}

public Connection setConn(){
   try {
    conn = DriverManager.getConnection(uri,userName,passWord);
   } catch (SQLException e) {
    log.error(e.getMessage());
   }
   return conn;
}
public void closeConn(){
   try {
    if(rs!=null){
     rs.close();
    }
    if(stmt!=null){
     stmt.close();
    }
    if(conn!=null){
     conn.close();
    }
   } catch (SQLException e) {
    log.error(e.getMessage());
   }
}
}

你可能感兴趣的:(java,apache,sql,jdbc,db2)