编程者交流中心 (http://linlin520.cc.topzj.com)
/*
 * Created on 2006-6-8
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package jxsafe.com;/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import java.io.*;
import java.util.Enumeration;
import java.util.Properties;
import java.sql.*;
public class proreadText {
  
  /**
   * --读取文件---
   * @inputStream java.io
   * @exception Exception
   **/
public void ttRead() throws Exception
{

FileInputStream is = new FileInputStream(new File("e:/db.properties"));
 //java.io.InputStream is =getClass().getResourceAsStream("e:/db.properties");
Properties dbProps = new Properties();
        try
        {
            dbProps.load(is);
        }
        catch(Exception e)
        {
            System.out.println("no");
            return;
        }
        createCon(dbProps);
}
  /**
   * --读取文件---
   * @drivers    驱动
   * @url         数据库URL
   * @user        数据库用户名
   * @password   数据库密码
   * @exception  Exception
   **/
public void createCon(Properties drpros) throws Exception
    {
   String user = null;
       String password = null;
       String drivers=drpros.getProperty("drivers");
     for(Enumeration propNames = drpros.propertyNames(); propNames.hasMoreElements();)
     {
     String name = (String)propNames.nextElement();
            if(name.endsWith(".url"))
            {
                String dbName = name.substring(0, name.lastIndexOf("."));
                String url = drpros.getProperty(dbName + ".url");
                if(url == null)
                {
                  System.out.println("您没有选择数据库");
                } 
                else{
                    user = drpros.getProperty(dbName + ".user");
                    password = drpros.getProperty(dbName + ".password");
                    try{
                     SqlClass sc=new SqlClass();
                      sc.setDriver(drivers);
                      sc.setUrl(url);
                     //sc.jdbc_thin(user,password,2);
                      Connection conn=sc.jdbc_oci(user,password);
                      System.out.println("用户"+user+"连接数据库成功");
                      System.out.println(conn.getTransactionIsolation());
                     System.out.println("数据库是否关闭:"+conn.isClosed());
                      sc.cleanUp(conn);
                      System.out.println("调用clearUP后数据库是否关闭:"+conn.isClosed());
                    }
                    catch(Exception e){
                     System.out.println("数据库用户名和密码不对");
                     return;
}
                }
            }
       }
    
    }
public static void main(String[] args)throws Exception {
proreadText t=new proreadText();
t.ttRead();
    
}
}