Я использую Oracle 11g XE и Java 8. Я разрабатываю настольное приложение и хочу создать пул соединений. Приложение зависает при выполнении pds.getConnection(); Я пробовал использовать простой JDBC, он работает нормально, так что это не проблема сети/БД.
Вот код, который я вызываю:
/**
* This returns DB connection from the DB Connection Pool
*
* @return
* @throws IOException
* @throws SQLException
*/
public static Connection getConnection() throws IOException, SQLException {
if (pds == null) {
initConnectionPool();
}
Connection conn = pds.getConnection();
System.out.println("Available connections after checkout: " + pds.getAvailableConnectionsCount());
System.out.println("Borrowed connections after checkout: " + pds.getBorrowedConnectionsCount());
return conn;
}
/**
* init DB Connection Pool
*
* @return
* @throws IOException
* @throws SQLException
*/
private static void initConnectionPool() throws IOException, SQLException {
Properties configProperties = Utils.getConfig();
// Get the PoolDataSource for UCP
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
// Set the connection factory first before all other properties
System.out.println("Class name :" + configProperties.getProperty("CONNECTION_FACTORY_CLASS_NAME"));
pds.setConnectionFactoryClassName(configProperties.getProperty("CONNECTION_FACTORY_CLASS_NAME"));
System.out.println("DB URL ==" + configProperties.getProperty("DB_URL"));
pds.setURL(configProperties.getProperty("DB_URL"));
System.out.println("DB User ==" + configProperties.getProperty("DB_USER"));
pds.setUser(configProperties.getProperty("DB_USER"));
System.out.println("Password==" + configProperties.getProperty("DB_PSWD"));
pds.setPassword(configProperties.getProperty("DB_PSWD"));
pds.setConnectionPoolName("JDBC_UCP_POOL");
// Default is 0. Set the initial number of connections to be created
// when UCP is started.
pds.setInitialPoolSize(Integer.parseInt(configProperties.getProperty("INITIAL_POOL_SIZE")));
// Default is 0. Set the minimum number of connections
// that is maintained by UCP at runtime.
pds.setMinPoolSize(Integer.parseInt(configProperties.getProperty("MIN_POOL_SIZE")));
// Default is Integer.MAX_VALUE (2147483647). Set the maximum number of
// connections allowed on the connection pool.
pds.setMaxPoolSize(Integer.parseInt(configProperties.getProperty("MAX_POOL_SIZE")));
}
/**
* Loads the config file and return instance of Properties
*
* @return Proterties
* @throws IOException
*/
public static Properties getConfig() throws IOException {
if (configProps != null)
return configProps;
configProps = new Properties();
FileInputStream in;
in = new FileInputStream("bin/resources/config.properties");
configProps.load(in);
in.close();
return configProps;
}
Используются следующие свойства:
DB_URL=jdbc:oracle:thin:@//localhost:1521/XE
INITIAL_POOL_SIZE=5
MIN_POOL_SIZE=5
MAX_POOL_SIZE=10
CONNECTION_FACTORY_CLASS_NAME=oracle.jdbc.pool.OracleDataSource
Подробнее здесь: https://stackoverflow.com/questions/488 ... connection
Приложение зависает при выполнении pds.getConnection() ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1731340630
Anonymous
Я использую Oracle 11g XE и Java 8. Я разрабатываю настольное приложение и хочу создать пул соединений. Приложение зависает при выполнении pds.getConnection(); Я пробовал использовать простой JDBC, он работает нормально, так что это не проблема сети/БД.
[b]Вот код, который я вызываю:[/b]
/**
* This returns DB connection from the DB Connection Pool
*
* @return
* @throws IOException
* @throws SQLException
*/
public static Connection getConnection() throws IOException, SQLException {
if (pds == null) {
initConnectionPool();
}
Connection conn = pds.getConnection();
System.out.println("Available connections after checkout: " + pds.getAvailableConnectionsCount());
System.out.println("Borrowed connections after checkout: " + pds.getBorrowedConnectionsCount());
return conn;
}
/**
* init DB Connection Pool
*
* @return
* @throws IOException
* @throws SQLException
*/
private static void initConnectionPool() throws IOException, SQLException {
Properties configProperties = Utils.getConfig();
// Get the PoolDataSource for UCP
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
// Set the connection factory first before all other properties
System.out.println("Class name :" + configProperties.getProperty("CONNECTION_FACTORY_CLASS_NAME"));
pds.setConnectionFactoryClassName(configProperties.getProperty("CONNECTION_FACTORY_CLASS_NAME"));
System.out.println("DB URL ==" + configProperties.getProperty("DB_URL"));
pds.setURL(configProperties.getProperty("DB_URL"));
System.out.println("DB User ==" + configProperties.getProperty("DB_USER"));
pds.setUser(configProperties.getProperty("DB_USER"));
System.out.println("Password==" + configProperties.getProperty("DB_PSWD"));
pds.setPassword(configProperties.getProperty("DB_PSWD"));
pds.setConnectionPoolName("JDBC_UCP_POOL");
// Default is 0. Set the initial number of connections to be created
// when UCP is started.
pds.setInitialPoolSize(Integer.parseInt(configProperties.getProperty("INITIAL_POOL_SIZE")));
// Default is 0. Set the minimum number of connections
// that is maintained by UCP at runtime.
pds.setMinPoolSize(Integer.parseInt(configProperties.getProperty("MIN_POOL_SIZE")));
// Default is Integer.MAX_VALUE (2147483647). Set the maximum number of
// connections allowed on the connection pool.
pds.setMaxPoolSize(Integer.parseInt(configProperties.getProperty("MAX_POOL_SIZE")));
}
/**
* Loads the config file and return instance of Properties
*
* @return Proterties
* @throws IOException
*/
public static Properties getConfig() throws IOException {
if (configProps != null)
return configProps;
configProps = new Properties();
FileInputStream in;
in = new FileInputStream("bin/resources/config.properties");
configProps.load(in);
in.close();
return configProps;
}
[b]Используются следующие свойства:[/b]
DB_URL=jdbc:oracle:thin:@//localhost:1521/XE
INITIAL_POOL_SIZE=5
MIN_POOL_SIZE=5
MAX_POOL_SIZE=10
CONNECTION_FACTORY_CLASS_NAME=oracle.jdbc.pool.OracleDataSource
Подробнее здесь: [url]https://stackoverflow.com/questions/48847267/the-application-hangs-while-executing-pds-getconnection[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия