打印本文 打印本文 关闭窗口 关闭窗口
java连接oracle,取io文件内容,子串替换(原作)!
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2698  更新时间:2009/4/22 22:05:06  文章录入:mintao  责任编辑:mintao

package common;
import java.sql.*;
import java.io.*;
import javax.naming.*;
import javax.sql.*;
import java.util.*;

public class DbAction{
        public Connection conn = null;
        public PreparedStatement stmt=null;

        public Properties getProperties(String str){
                Properties properties = new Properties();
                           try{
                                        InputStream is =getClass().getResourceAsStream("/"+str);
                                        properties.load(is);
                                        if(is != null)
                                        is.close();
                                        }
                                catch(IOException ioexception){
                                                   System.out.println("Open config file failure.");
                                           }
                                catch(NullPointerException e){
                                        System.out.println("is is null");
                                }
                                return properties;
        }
        public synchronized void DbConnect(){
           String strCon=null;
           Properties properties = getProperties("datasource.properties");
           String username = properties.getProperty("username");
           String password = properties.getProperty("password");
           String hostname = properties.getProperty("hostname");
           String hostip = properties.getProperty("hostip");
           String hostport = properties.getProperty("hostport");

                 try
                        {
                         Class.forName("oracle.jdbc.driver.OracleDriver");
                        }
                        catch(ClassNotFoundException classnotfoundexception)
                        {
                                System.out.println("Could not load the driver.");
                                classnotfoundexception.printStackTrace();
                        }
                   strCon = "jdbc:oracle:thin:@"+hostip+":"+hostport+":"+hostname;
                 try
                        {
                           conn = DriverManager.getConnection(strCon,username,password);
                        }
                        catch(SQLException sqlexception)
                        {
                                System.out.println("Creat connection error.");
                                sqlexception.printStackTrace();
                        }
//          try{
//   Context initContext = new InitialContext();  //连接池用
//   Context envContext = (Context) initContext.lookup("java:/comp/env");
//   DataSource ds = (DataSource) envContext.lookup("jdbc/oracle");
//   conn = ds.getConnection();
//          }
//    catch(NamingException ne){
//     ne.printStackTrace();
//    }
//    catch(SQLException se){
//     se.printStackTrace();
//    }
                                }
        public String sqlSearch(String str){
                   String sql=null;
                   Properties properties = getProperties("sql.properties");
                   sql = properties.getProperty(str);
                   return sql;
                }
        public ResultSet dbSelect(String sql){
                ResultSet rs=null;
                try{
                   &n

[1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口