Основные понятия JDBC, Объединение в потоки и Потоки

Я всегда использовал JDBC в JavaSE в однопоточной среде. Но теперь мне нужно использовать пул соединений и позволить многим потокам взаимодействовать с базой данных (MSSQL и Oracle), и мне трудно это сделать, так как мне кажется, что мне не хватает фундаментального понимания API.

AFAIK после подключения и входаConnection представляет физическое TCP / IP-соединение с базой данных. Это создаетStatement(s), которые можно рассматривать как взаимодействие SQL с базой данных черезConnection.

Where does the transaction and rollback comes in ? Is it at the Connection or Statement level. Is it safe that 'one' Connection create N statements and give it to diferent threads so to let each one own the use of that Statement ?

Если нет, то и после настройки пула примерно так:

OracleDataSource ods = new OracleDataSource(); 
ods.setURL("jdbc:oracle:thin:@tnsentryname");
ods.setUser("u");
ods.setPassword("p");

BTW, where do I set the connection pool size ?

Is this what I would be doing in each thread in order to correctly use the connection ?

// метод запуска

Connection conn = ods.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("the sql");
// do what I need to do with rs
rs.close();
int updateStatus = stmt.executeUpdate("the update");
stmt.close();
conn.close();

// метод запуска потока

If any physical Connection of the Pool somehow crashes or disconects, will the pool automaticaly try to reconnect and inject the new connection in the pool so that subsequent pool.getConnection() will just get a health connection ?

Большое спасибо и простите мой плохой английский, пожалуйста.

Ответы на вопрос(7)

Ваш ответ на вопрос