我参照别人的代码自己写了段数据库库连接池的代码,其中用到是.property文件格式是怎么样的?
在api中看了也没什么认识,请大家帮忙!

解决方案 »

  1.   


    import java.util.Properties;
    import java.io.FileInputStream;public class Test {
    public static void main(String[] args) throws Exception{
    FileInputStream inStream = new FileInputStream("./db.properties");
    Properties property = new Properties();

    property.load(inStream);//把指定的流加载到内存中来
    String db=property.getProperty("db");//从内存中读出Key为db的Value
    //中文编码转换
    /*db= new String(
    db.getBytes("ISO8859-1"),"UTF8");*/
    System.out.println(db);
    System.out.println(property.getProperty("username"));

    /*db.properties里的内容,它里面存的是键值对
     *db=oracle
     *url=192.16.0.126
     *username=openlab
     *password=open123
     *
     */
    }}
      

  2.   


    jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost/cmsdb?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8jdbc.username=rootjdbc.password=123hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect