0

I have a spring boot 1.5.22 app and i am trying to connect to oracle 10g with tomcat-jdbc and ojdbc6.
i have the datasource getproperties() function to connect to my db :

DataSource dataSourceProperties()  {
     DataSource ds=null;
    try {
    ds = DataSourceBuilder.create()
            .driverClassName("oracle.jdbc.OracleDriver")
            .url("jdbc:oracle:thin:@//host:port/DBname")
            .username("xxx")
            .password("xxx")
            .build();
    }catch (Exception e) {
        System.out.println(e.toString());}

when the url was with this SID format : jdbc:oracle:thin:@host:port:DBname i got an oracle error : refused:ROR=(code=12505)(EMFI=4) when i changed it to jdbc:oracle:thin:@host:port/DBname i got java.sql.SQLException: String index out of range: -1 and finally this format jdbc:oracle:thin:@//host:port/DBname and still getting java.sql.SQLException: String index out of range: -1

that's how i make call to that function in getConnection function :

public Connection getConnection() throws SQLException
    {  
        
        Connection conn=null;
            try {
                this.ds=this.dataSourceProperties();
                conn=ds.getConnection();
            }catch (SQLException e ) {
                System.out.println(e.toString());
                
            }
            return conn;}

here are somme error logs :

2021-08-16 18:33:59.926 ERROR 22476 --- [bio-8080-exec-1] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

java.sql.SQLException: String index out of range: -1
        at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:332) ~[tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212) ~[tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:736) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:668) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:483) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) [tomcat-jdbc-8.5.43.jar:na]
        at com..web.services.DBConnection.getConnection(DBConnection.java:68) 

[classes/:na]
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
java.sql.SQLException: String index out of range: -1
Mon Aug 16 18:33:59 CEST 2021
java.lang.NullPointerException

here are new error logs after modifying the url to the correct format jdbc:oracle:thin://xx:1509/xxx

2021-08-17 11:25:27.368 ERROR 15440 --- [bio-8080-exec-5] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

java.sql.SQLException: Connection refused: connect
        at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:223) ~[jdbc-oracle-11.2.0.3.jar:na]
        at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:100) ~[jdbc-oracle-11.2.0.3.jar:na]
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:146) ~[jdbc-oracle-11.2.0.3.jar:na]
        at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:319) ~[tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212) ~[tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:736) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:668) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:483) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) [tomcat-jdbc-8.5.43.jar:na]
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) [tomcat-jdbc-8.5.43.jar:na]


    
    
    
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Have you looked at other answers like this one? https://stackoverflow.com/a/16632783/5047819 – Anders Lindgren Aug 16 '21 at 17:02
  • Set logging level to debug (at least) for org.apache.tomcat.jdbc.pool and see what it shows. Also: I would remove all those "catch (Exception) { print and do nothing else }" blocks. You may be hiding something important here – Marcin Wroblewski Aug 16 '21 at 19:45
  • @MarcinWroblewski thank you for your response, but how to make o logger for org.apache.tomcat.jdbc.pool please? i edited the post and added some error logs – Manel BEN AMARA Aug 17 '21 at 09:31
  • @AndersLindgren thank you for your response, the format suggested in the link worked for me but i am still getting "Unable to create initial connections of pool" and "connection refused" !! i edited the post and added some error logs – Manel BEN AMARA Aug 17 '21 at 09:32
  • @ManelBENAMARA look at this answer as well: https://stackoverflow.com/a/18196876/5047819 and https://www.tekstream.com/resource-center/ora-12505-tns-listener-does-not-currently-know-of-sid-given-in-connect-descriptor/ and http://www.dba-oracle.com/sf_ora_12505_tns_listener_does_not_currently_know_of_sid_given_in_connect_descriptor.htm – Anders Lindgren Aug 17 '21 at 12:46

1 Answers1

0

Solved : this one worked for me :)

jdbc:oracle:thin://host:port/ServiceName

An example:

jdbc:oracle:thin://hostname:1509/ServiceName(or DatabaseName)