Connection pooling in java example with oracle
- Oracle connection pool example
- Java connection pooling
- Oracle database connection with JDBC
- Implementing own Connection pooling in Java
- how to implement connection pooling in java with example
Here we are creating a class and declaring all database information. This call will execute only one time at the program beaning. If you are using Web server, this call will execute one time at the beginning of the server start.
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class ConnectionPool {
- static Connection con;
- static Statement st;
- static{
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- try {
- con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE","system","8040");
- st=con.createStatement();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
After Database connection successfully establish , you can use statement object for other transaction.
Example
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class TestConnectionPoll {
- public static void main(String[] args) throws SQLException {
- ResultSet rs=ConnectionPool.st.executeQuery("select * from root.website");
- while(rs.next()){
- System.out.println(rs.getString(1));
- }
- }
- }
Comments
Post a Comment