读取properties文件

package com.dvision;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;


import javax.sql.DataSource;


import org.apache.commons.dbcp.*;
public class JdbcUtil {
private static DataSource myDataSource = null;
static {
try {
Class.forName("com.mysql.jdbc.Driver");
Properties prop = new Properties();
InputStream is = JdbcUtil.class.getClassLoader().getResourceAsStream("dbcpconfig.properties");
prop.load(is);
myDataSource = BasicDataSourceFactory.createDataSource(prop);
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}
public synchronized static Connection getConnection() throws SQLException {
return myDataSource.getConnection();
}
}

你可能感兴趣的:(properties,exception,class)